예제 #1
0
 def test_setup_nohealth2(self):
     core = ControllerCore(self.prov_client, self.ENGINE, "controller",
                           {PROVISIONER_VARS_KEY : self.prov_vars,
                            MONITOR_HEALTH_KEY : False
                            })
     self.assertEqual(core.health_monitor, None)
     #should be ignored (no exception)
     core.new_heartbeat('notarealheartbeat')
예제 #2
0
    def test_faily_engine(self):
        core = ControllerCore(self.prov_client, "%s.FailyEngine" % __name__,
                              "controller",
                              {PROVISIONER_VARS_KEY : self.prov_vars})
        yield core.run_recovery()
        yield core.run_initialize()

        #exception should not bubble up
        yield core.run_decide()
예제 #3
0
    def test_whole_state(self):
        state = FakeControllerState()
        core = ControllerCore(self.prov_client, self.ENGINE, "controller",
                              state=state, conf={MONITOR_HEALTH_KEY:True})

        # setup 3 instances that are "recovered", should see a dump_state call to provisioner
        # for 2 of them
        state.instances['i1'] = Mock(instance_id='i1', state=InstanceStates.RUNNING,
                                     health=InstanceHealthState.OK, public_ip="i1pubip",
                                     private_ip="i1privip", state_time=3, iaas_id="i-i1")
        state.instances['i2'] = Mock(instance_id='i2', state=InstanceStates.TERMINATED,
                                     health=InstanceHealthState.UNKNOWN, public_ip=None,
                                     private_ip=None, state_time=4, iaas_id="i-i2")
        state.instances['i3'] = Mock(instance_id='i3', state=InstanceStates.REQUESTED,
                                     health=InstanceHealthState.UNKNOWN, public_ip=None,
                                     private_ip=None, iaas_id=None, state_time=1)

        whole_state = yield core.whole_state()
        log.debug("whole_state: %s", whole_state)
        self.assertEqual(whole_state['de_state'], de_states.UNKNOWN)
        self.assertEqual(whole_state['de_conf_report'], None)
        instances = whole_state['instances']
        self.assertEqual(len(instances), 3)

        i1 = instances['i1']
        self.assertEqual(i1['iaas_state'], InstanceStates.RUNNING)
        self.assertEqual(i1['iaas_state_time'], 3)
        self.assertEqual(i1['heartbeat_state'], InstanceHealthState.OK)
        self.assertEqual(i1['heartbeat_time'], -1)
        self.assertEqual(i1['public_ip'], "i1pubip")
        self.assertEqual(i1['private_ip'], "i1privip")
        self.assertEqual(i1['iaas_id'], "i-i1")

        i2 = instances['i2']
        self.assertEqual(i2['iaas_state'], InstanceStates.TERMINATED)
        self.assertEqual(i2['iaas_state_time'], 4)
        self.assertEqual(i2['heartbeat_state'], InstanceHealthState.UNKNOWN)
        self.assertEqual(i2['heartbeat_time'], -1)
        self.assertEqual(i2['public_ip'], None)
        self.assertEqual(i2['private_ip'], None)
        self.assertEqual(i2['iaas_id'], "i-i2")

        i3 = instances['i3']
        self.assertEqual(i3['iaas_state'], InstanceStates.REQUESTED)
        self.assertEqual(i3['iaas_state_time'], 1)
        self.assertEqual(i3['heartbeat_state'], InstanceHealthState.UNKNOWN)
        self.assertEqual(i3['heartbeat_time'], -1)
        self.assertEqual(i3['public_ip'], None)
        self.assertEqual(i3['private_ip'], None)
        self.assertEqual(i3['iaas_id'], None)
예제 #4
0
    def test_initialize_no_instance_recovery(self):
        state = FakeControllerState()
        core = ControllerCore(self.prov_client, self.ENGINE, "controller",
                              state=state, conf={'base1' : "avaf",
                                                 'base2' : [1,2,3]})

        state.engine_extraconf = {'extra1' : "123456"}

        yield core.run_recovery()
        yield core.run_initialize()
        self.assertEqual(state.recover_count, 1)
        self.assertEqual(core.engine.initialize_count, 1)
        self.assertEqual(core.engine.initialize_conf, {'base1' : "avaf",
                                                       'base2' : [1,2,3],
                                                       'extra1' : "123456"})

        self.assertEqual(len(self.prov_client.dump_state_reqs), 0)
예제 #5
0
    def test_initialize_with_instance_recovery(self):
        state = FakeControllerState()
        core = ControllerCore(self.prov_client, self.ENGINE, "controller",
                              state=state)

        # setup 3 instances that are "recovered", should see a dump_state call to provisioner
        # for 2 of them
        state.instances['i1'] = Mock(instance_id='i1', state=InstanceStates.RUNNING)
        state.instances['i2'] = Mock(instance_id='i2', state=InstanceStates.TERMINATED)
        state.instances['i3'] = Mock(instance_id='i3', state=InstanceStates.PENDING)

        yield core.run_recovery()
        yield core.run_initialize()
        self.assertEqual(state.recover_count, 1)
        self.assertEqual(core.engine.initialize_count, 1)

        self.assertEqual(len(self.prov_client.dump_state_reqs), 1)
        node_ids = set(self.prov_client.dump_state_reqs[0])
        self.assertEqual(node_ids, set(('i1', 'i3')))
예제 #6
0
 def test_setup_health(self):
     core = ControllerCore(self.prov_client, self.ENGINE, "controller",
                           {PROVISIONER_VARS_KEY : self.prov_vars,
                            MONITOR_HEALTH_KEY : True, HEALTH_BOOT_KEY:1,
                            HEALTH_ZOMBIE_KEY:2, HEALTH_MISSING_KEY:3
                            })
     health = core.health_monitor
     self.assertNotEqual(health, None)
     self.assertEqual(health.boot_timeout, 1)
     self.assertEqual(health.zombie_timeout, 2)
     self.assertEqual(health.missing_timeout, 3)
예제 #7
0
    def test_deferred_engine(self):
        core = ControllerCore(self.prov_client, "%s.DeferredEngine" % __name__,
                              "controller",
                              {PROVISIONER_VARS_KEY : self.prov_vars})

        yield core.run_recovery()
        yield core.run_initialize()

        self.assertEqual(1, core.engine.initialize_count)

        self.assertEqual(0, core.engine.decide_count)
        yield core.run_decide()
        self.assertEqual(1, core.engine.decide_count)
        yield core.run_decide()
        self.assertEqual(2, core.engine.decide_count)

        self.assertEqual(0, core.engine.reconfigure_count)
        yield core.run_reconfigure({})
        self.assertEqual(1, core.engine.reconfigure_count)