Permalink
Browse files

Stop the serving info setter replacing the cert from the cert updater.

  • Loading branch information...
1 parent bad2931 commit 0d64508f8005ea84c141ed392389fbaef0e70b30 @howbazaar howbazaar committed Sep 22, 2016
@@ -57,12 +57,21 @@ func ServingInfoSetterManifold(config ServingInfoSetterConfig) dependency.Manifo
if err != nil {
return nil, err
}
+ existing, hasInfo := agent.CurrentConfig().StateServingInfo()
for _, job := range machine.Jobs() {
if job.NeedsState() {
info, err := apiState.StateServingInfo()
if err != nil {
return nil, errors.Errorf("cannot get state serving info: %v", err)
}
+ if hasInfo {
+ // Use the existing Cert as it may have been updated already
+ // by the cert updater worker to have this machine's IP address
+ // as part of the cert. This changed cert is never put back into
+ // the database, so it isn't reflected in the copy we have got
+ // from apiState.
+ info.Cert = existing.Cert
+ }
err = agent.ChangeConfig(func(config coreagent.ConfigSetter) error {
config.SetStateServingInfo(info)
return nil
@@ -100,11 +100,7 @@ func (s *ServingInfoSetterSuite) TestEntityLookupFailure(c *gc.C) {
c.Assert(err, gc.ErrorMatches, "boom")
}
-func (s *ServingInfoSetterSuite) TestJobManageEnviron(c *gc.C) {
- // State serving info should be set for machines with JobManageEnviron.
- const mockAPIPort = 1234
-
- a := &mockAgent{}
+func (s *ServingInfoSetterSuite) startManifold(c *gc.C, a coreagent.Agent, mockAPIPort int) {
apiCaller := basetesting.APICallerFunc(
func(objType string, version int, id, request string, args, response interface{}) error {
c.Assert(objType, gc.Equals, "Agent")
@@ -118,6 +114,7 @@ func (s *ServingInfoSetterSuite) TestJobManageEnviron(c *gc.C) {
case "StateServingInfo":
result := response.(*params.StateServingInfo)
*result = params.StateServingInfo{
+ Cert: testing.CACert,
APIPort: mockAPIPort,
}
default:
@@ -133,10 +130,37 @@ func (s *ServingInfoSetterSuite) TestJobManageEnviron(c *gc.C) {
w, err := s.manifold.Start(context)
c.Assert(w, gc.IsNil)
c.Assert(err, gc.Equals, dependency.ErrUninstall)
+}
+
+func (s *ServingInfoSetterSuite) TestJobManageEnviron(c *gc.C) {
+ // State serving info should be set for machines with JobManageEnviron.
+ const mockAPIPort = 1234
+
+ a := &mockAgent{}
+ s.startManifold(c, a, mockAPIPort)
+
+ // Verify that the state serving info was actually set.
+ c.Assert(a.conf.ssiSet, jc.IsTrue)
+ c.Assert(a.conf.ssi.APIPort, gc.Equals, mockAPIPort)
+ c.Assert(a.conf.ssi.Cert, gc.Equals, testing.CACert)
+}
+
+func (s *ServingInfoSetterSuite) TestJobManageEnvironNotOverwriteCert(c *gc.C) {
+ // State serving info should be set for machines with JobManageEnviron.
+ const mockAPIPort = 1234
+
+ a := &mockAgent{}
+ existingCert := "some cert updated by certupdater"
+ a.conf.SetStateServingInfo(params.StateServingInfo{
+ Cert: existingCert,
+ })
+
+ s.startManifold(c, a, mockAPIPort)
// Verify that the state serving info was actually set.
c.Assert(a.conf.ssiSet, jc.IsTrue)
c.Assert(a.conf.ssi.APIPort, gc.Equals, mockAPIPort)
+ c.Assert(a.conf.ssi.Cert, gc.Equals, existingCert)
}
func (s *ServingInfoSetterSuite) TestJobHostUnits(c *gc.C) {
@@ -200,6 +224,10 @@ func (mc *mockConfig) Tag() names.Tag {
return mc.tag
}
+func (mc *mockConfig) StateServingInfo() (params.StateServingInfo, bool) {
+ return mc.ssi, mc.ssiSet
+}
+
func (mc *mockConfig) SetStateServingInfo(info params.StateServingInfo) {
mc.ssiSet = true
mc.ssi = info

0 comments on commit 0d64508

Please sign in to comment.