Ejemplo n.º 1
0
 def setUp(self):
     self.provisioner = FakeProvisionerClient()
     self.state = ControllerCoreState(ControllerStore())
     self.prov_vars = {"foo" : "bar"}
     self.controller_name = "fakey"
     self.control = ControllerCoreControl(self.provisioner, self.state,
                                          self.prov_vars,
                                          self.controller_name)
Ejemplo n.º 2
0
class ControllerCoreControlTests(unittest.TestCase):
    def setUp(self):
        self.provisioner = FakeProvisionerClient()
        self.state = ControllerCoreState(ControllerStore())
        self.prov_vars = {"foo" : "bar"}
        self.controller_name = "fakey"
        self.control = ControllerCoreControl(self.provisioner, self.state,
                                             self.prov_vars,
                                             self.controller_name)

    def test_configure_1(self):
        self.control.configure(None)
        self.assertEqual(self.control.sleep_seconds, 5.0)
        self.assertEqual(self.control.prov_vars, self.prov_vars)

    def test_configure_2(self):
        self.control.configure({})
        self.assertEqual(self.control.sleep_seconds, 5.0)
        self.assertEqual(self.control.prov_vars, self.prov_vars)

    def test_configure_3(self):
        params = {"timed-pulse-irregular" : 3000,
                  PROVISIONER_VARS_KEY : {"blah": "blah"}}
        self.control.configure(params)
        self.assertEqual(self.control.sleep_seconds, 3.0)
        self.assertEqual(self.control.prov_vars, {"blah": "blah"})

    def test_launch(self):
        desc = {'i1' : LaunchItem(1, "small", "chicago", None)}
        launch_id, launch_desc = self.control.launch("dt", desc, extravars={"v1": 1})

        instance_ids = launch_desc['i1'].instance_ids
        self.assertEqual(len(instance_ids), 1)

        #check that right info got added to state
        instance_id = instance_ids[0]
        instance = self.state.instances[instance_id]
        self.assertEqual(instance.instance_id, instance_id)
        self.assertEqual(instance.launch_id, launch_id)
        self.assertEqual(instance.site, "chicago")
        self.assertEqual(instance.allocation, "small")

        # and provisionerclient called
        self.assertEqual(len(self.provisioner.launches), 1)
        launch = self.provisioner.launches[0]
        self.assertEqual(launch['launch_id'], launch_id)
        self.assertEqual(launch['dt'], "dt")
        # vars are merged result
        self.assertEqual(launch['vars']['foo'], "bar")
        self.assertEqual(launch['vars']['v1'], 1)
        self.assertEqual(launch['subscribers'], (self.controller_name,))
        self.assertEqual(launch['launch_description'], launch_desc)