예제 #1
0
파일: test_dtrs.py 프로젝트: lelou6666/epu
    def setUp(self):
        self.amqp_uri = "memory://hello"
        self.threads = []
        self.dtrs = DTRS(amqp_uri=self.amqp_uri)

        self._spawn_process(self.dtrs.start)

        # this sucks. sometimes service doesn't bind its queue before client
        # sends a message to it.
        time.sleep(0.05)

        self.dtrs_client = DTRSClient(dashi=self.dtrs.dashi)

        self.caller = "asterix"
        site_definition = {
            "type": "fake"
        }
        self.dtrs.add_site("nimbus-test", site_definition)

        credentials_definition = {
            'access_key': 'myec2access',
            'secret_key': 'myec2secret',
            'key_name': 'nimbus'
        }
        self.dtrs.add_credentials(self.caller, "nimbus-test", credentials_definition)
예제 #2
0
class DTRSTests(unittest.TestCase):
    def setUp(self):
        self.amqp_uri = "memory://hello"
        self.threads = []
        self.dtrs = DTRS(amqp_uri=self.amqp_uri)

        self._spawn_process(self.dtrs.start)

        # this sucks. sometimes service doesn't bind its queue before client
        # sends a message to it.
        time.sleep(0.05)

        self.dtrs_client = DTRSClient(dashi=self.dtrs.dashi)

        self.caller = "asterix"
        site_definition = {"type": "fake"}
        self.dtrs.add_site("nimbus-test", site_definition)

        credentials_definition = {"access_key": "myec2access", "secret_key": "myec2secret", "key_name": "nimbus"}
        self.dtrs.add_credentials(self.caller, "nimbus-test", credentials_definition)

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

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

    def _shutdown_processes(self, threads):
        self.dtrs.dashi.cancel()
        tevent.joinall(threads)

    def tearDown(self):
        self.shutdown_procs()

    def test_dtrs_lookup(self):
        dt_definition = {"mappings": {"nimbus-test": {"iaas_image": "fake-image", "iaas_allocation": "m1.small"}}}
        self.dtrs.add_dt(self.caller, "base-cluster-1", dt_definition)

        allocation_override = "m1.xlarge"
        req_node = {"site": "nimbus-test", "allocation": allocation_override}
        result = self.dtrs_client.lookup(self.caller, "base-cluster-1", req_node)
        node = result["node"]
        self.assertTrue("iaas_image" in node)
        self.assertEqual(node["iaas_allocation"], allocation_override)

        try:
            self.dtrs_client.lookup(self.caller, "this-dt-doesnt-exist", node)
        except DeployableTypeLookupError, e:
            log.info("Got expected error: " + str(e))
        else:
예제 #3
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)
예제 #4
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