Exemplo n.º 1
0
    def spawn_procs(self):
        self.dtrs = DTRS(amqp_uri=self.amqp_uri, sysname=self.sysname)
        self._spawn_process(self.dtrs.start)

        self.provisioner = ProvisionerService(sites=self.sites,
                                              store=self.store,
                                              context_client=self.context_client,
                                              notifier=self.notifier,
                                              amqp_uri=self.amqp_uri,
                                              sysname=self.sysname,
                                              default_user=self.default_user,
                                              record_reaping_max_age=self.record_reaping_max_age)
        self._spawn_process(self.provisioner.start)

        self.provisioner.ready_event.wait()

        client_topic = "provisioner_client_%s" % uuid.uuid4()

        self.client_dashi = bootstrap.dashi_connect(client_topic, amqp_uri=self.amqp_uri,
                sysname=self.sysname)

        self.client = ProvisionerClient(self.client_dashi)
Exemplo n.º 2
0
class BaseProvisionerServiceTests(unittest.TestCase):

    def __init__(self, *args, **kwargs):
        super(BaseProvisionerServiceTests, self).__init__(*args, **kwargs)
        DashiConnection.consumer_timeout = 0.01
        # these are to be set in a subclass' setUp()
        self.store = None
        self.notifier = None
        self.sites = None
        self.context_client = None
        self.client_dashi = None
        self.default_user = '******'
        self.sysname = "testsysname-%s" % str(uuid.uuid4())
        self.amqp_uri = "amqp://*****:*****@localhost/"
        self.record_reaping_max_age = 3600
        self.threads = []

    def assertStoreNodeRecords(self, state, *node_ids):
        for node_id in node_ids:
            node = self.store.get_node(node_id)
            self.assertTrue(node)
            self.assertEqual(node['state'], state)

    def assertNoStoreNodeRecords(self, *node_ids):
        for node_id in node_ids:
            node = self.store.get_node(node_id)
            self.assertEqual(node, None)

    def assertStoreLaunchRecord(self, state, launch_id):
        launch = self.store.get_launch(launch_id)
        self.assertTrue(launch)
        self.assertEqual(launch['state'], state)

    def assertNoStoreLaunchRecord(self, launch_id):
        launch = self.store.get_launch(launch_id)
        self.assertEqual(launch, None)

    def spawn_procs(self):
        self.dtrs = DTRS(amqp_uri=self.amqp_uri, sysname=self.sysname)
        self._spawn_process(self.dtrs.start)

        self.provisioner = ProvisionerService(sites=self.sites,
                                              store=self.store,
                                              context_client=self.context_client,
                                              notifier=self.notifier,
                                              amqp_uri=self.amqp_uri,
                                              sysname=self.sysname,
                                              default_user=self.default_user,
                                              record_reaping_max_age=self.record_reaping_max_age)
        self._spawn_process(self.provisioner.start)

        self.provisioner.ready_event.wait()

        client_topic = "provisioner_client_%s" % uuid.uuid4()

        self.client_dashi = bootstrap.dashi_connect(client_topic, amqp_uri=self.amqp_uri,
                sysname=self.sysname)

        self.client = ProvisionerClient(self.client_dashi)

    def shutdown_procs(self):
        self._shutdown_processes(self.threads)

    def _spawn_process(self, process):
        thread = tevent.spawn(process)
        self.threads.append(thread)

    def _shutdown_processes(self, threads):
        self.dtrs.stop()
        self.provisioner.stop()
        tevent.joinall(threads)

    def load_dtrs(self):
        site_definition = {
            "type": "fake"
        }
        self.dtrs.add_site("fake-site1", site_definition)

        caller = "asterix"
        credentials_definition = {
            'access_key': 'myec2access',
            'secret_key': 'myec2secret',
            'key_name': 'ooi'
        }
        self.dtrs.add_credentials(caller, "fake-site1", credentials_definition)

        dt1 = {
            'mappings': {
                'fake-site1': {
                    'iaas_image': 'fake-image',
                    'iaas_allocation': 'm1.small'
                }
            }
        }

        dt2 = {
            'mappings': {
                'fake-site1': {
                    'iaas_image': '${image_id}',
                    'iaas_allocation': 'm1.small'
                }
            }
        }

        self.dtrs.add_dt(caller, "empty", dt1)
        self.dtrs.add_dt(caller, "empty-with-vars", dt2)

    def tearDown(self):
        self.shutdown_procs()
        if self.client_dashi:
            self.client_dashi.disconnect()
        self.teardown_store()

    def setup_store(self):
        return ProvisionerStore()

    def teardown_store(self):
        return