Пример #1
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:
Пример #2
0
    def block_until_ready(self, deployment_str, dashi):
        """Blocks until all of the services in a deployment are contacted
        """

        deployment = parse_deployment(yaml_str=deployment_str)

        for provisioner_name in deployment.get('provisioners', {}).iterkeys():
            provisioner = ProvisionerClient(dashi, topic=provisioner_name)
            self._block_on_call(provisioner.describe_nodes)

        for epum_name in deployment.get('epums', {}).iterkeys():
            epum = EPUManagementClient(dashi, epum_name)
            self._block_on_call(epum.list_domains)

        for node in deployment.get('nodes', {}).itervalues():
            for eeagent_name in node.get('eeagents', {}).iterkeys():
                eeagent = EEAgentClient(dashi=dashi,
                                        ee_name=eeagent_name,
                                        handle_heartbeat=False)
                self._block_on_call(eeagent.dump, kwargs={'rpc': True})

        for pd_name in deployment.get('process-dispatchers', {}).iterkeys():
            pd = ProcessDispatcherClient(dashi, pd_name)
            self._block_on_call(pd.describe_processes)

        for dt_name in deployment.get('dt_registries', {}).iterkeys():
            dtrs = DTRSClient(dashi, topic=dt_name)
            self._block_on_call(dtrs.list_sites)
Пример #3
0
    def get_clients(self, deployment_str, dashi):
        """returns a dictionary of epu clients, indexed by their topic name
        """

        deployment = parse_deployment(yaml_str=deployment_str)

        clients = {}

        for provisioner_name in deployment.get('provisioners', {}).iterkeys():
            client = ProvisionerClient(dashi, topic=provisioner_name)
            clients[provisioner_name] = client

        for epum_name in deployment.get('epums', {}).iterkeys():
            client = EPUManagementClient(dashi, epum_name)
            clients[epum_name] = client

        for node in deployment.get('nodes', {}).itervalues():
            for eeagent_name in node.get('eeagents', {}).iterkeys():
                client = EEAgentClient(dashi=dashi,
                                       ee_name=eeagent_name,
                                       handle_heartbeat=False)
                clients[eeagent_name] = client

        for pd_name in deployment.get('process-dispatchers', {}).iterkeys():
            client = ProcessDispatcherClient(dashi, pd_name)
            clients[pd_name] = client

        for dt_name in deployment.get('dt_registries', {}).iterkeys():
            client = DTRSClient(dashi, topic=dt_name)
            clients[dt_name] = client

        return clients
Пример #4
0
    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)
Пример #5
0
def main():
    f = open("bootconf.json", "r")
    conf_dict = json.load(f)

    CFG = DotDict(conf_dict['epu']["run_config"]["config"])
    CFG.server.amqp.vhost = '/'

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

    client_dashi = bootstrap.dashi_connect(client_topic, CFG=CFG)

    dtrs_client = DTRSClient(dashi=client_dashi)
    for i in range(0, 3):
        try:
            sites = dtrs_client.list_sites()
            print sites
            break
        except Exception, ex:
            print ex
            time.sleep(5);
Пример #6
0
def main():
    f = open("bootconf.json", "r")
    conf_dict = json.load(f)

    rabbitmq_conf = conf_dict['epu']["run_config"]["config"]["server"]["amqp"]
    rabbitmq_host = rabbitmq_conf["host"]
    rabbitmq_username = rabbitmq_conf["username"]
    rabbitmq_password = rabbitmq_conf["password"]

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


    uri = "amqp://%s:%s@%s" % (rabbitmq_username, rabbitmq_password, rabbitmq_host)
    #dtrs = DTRS(amqp_uri=uri)
    client_dashi = bootstrap.dashi_connect(client_topic, amqp_uri=uri)

    dtrs_client = DTRSClient(dashi=client_dashi)
    sites = dtrs_client.list_sites()
    print sites

    return 0
Пример #7
0
def main():
    f = open("bootconf.json", "r")
    conf_dict = json.load(f)

    rabbitmq_conf = conf_dict['epu']["run_config"]["config"]["server"]["amqp"]
    rabbitmq_host = rabbitmq_conf["host"]
    rabbitmq_username = rabbitmq_conf["username"]
    rabbitmq_password = rabbitmq_conf["password"]

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

    uri = "amqp://%s:%s@%s" % (rabbitmq_username, rabbitmq_password,
                               rabbitmq_host)
    #dtrs = DTRS(amqp_uri=uri)
    client_dashi = bootstrap.dashi_connect(client_topic, amqp_uri=uri)

    dtrs_client = DTRSClient(dashi=client_dashi)
    sites = dtrs_client.list_sites()
    print sites

    return 0
Пример #8
0
def main():
    f = open("bootconf.json", "r")
    conf_dict = json.load(f)

    rabbitmq_conf = conf_dict['epu']["run_config"]["config"]["server"]["amqp"]
    rabbitmq_host = rabbitmq_conf["host"]
    rabbitmq_username = rabbitmq_conf["username"]
    rabbitmq_password = rabbitmq_conf["password"]

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


    uri = "amqp://%s:%s@%s" % (rabbitmq_username, rabbitmq_password, rabbitmq_host)
    client_dashi = bootstrap.dashi_connect(client_topic, amqp_uri=uri)

    dtrs_client = DTRSClient(dashi=client_dashi)
    for i in range(0, 3):
        try:
            sites = dtrs_client.list_sites()
            print sites
            break
        except Exception, ex:
            print ex
            time.sleep(5);
Пример #9
0
def main():
    f = open("bootconf.json", "r")
    conf_dict = json.load(f)

    rabbitmq_conf = conf_dict['epu']["run_config"]["config"]["server"]["amqp"]
    rabbitmq_host = rabbitmq_conf["host"]
    rabbitmq_username = rabbitmq_conf["username"]
    rabbitmq_password = rabbitmq_conf["password"]

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

    uri = "amqp://%s:%s@%s" % (rabbitmq_username, rabbitmq_password,
                               rabbitmq_host)
    client_dashi = bootstrap.dashi_connect(client_topic, amqp_uri=uri)

    dtrs_client = DTRSClient(dashi=client_dashi)
    for i in range(0, 3):
        try:
            sites = dtrs_client.list_sites()
            print sites
            break
        except Exception, ex:
            print ex
            time.sleep(5)
Пример #10
0
class TestPhantomIntegration(unittest.TestCase, TestFixture):

    def setUp(self):

        if not os.environ.get('INT'):
            raise SkipTest("Slow integration test")

        try:
            from epuharness.harness import EPUHarness  # noqa
        except ImportError:
            raise SkipTest("epuharness not available.")
        try:
            from epu.mocklibcloud import MockEC2NodeDriver  # noqa
        except ImportError:
            raise SkipTest("sqlalchemy not available.")

        self.exchange = "testexchange-%s" % str(uuid.uuid4())
        self.sysname = "testsysname-%s" % str(uuid.uuid4())
        self.user = default_user

        self.epuh_persistence = os.environ.get('EPUHARNESS_PERSISTENCE_DIR', '/tmp/SupD/epuharness')
        if os.path.exists(self.epuh_persistence):
            raise SkipTest("EPUHarness running. Can't run this test")

        # Set up fake libcloud and start deployment
        self.setup_harness(exchange=self.exchange, sysname=self.sysname)
        self.addCleanup(self.cleanup_harness)

        self.epuharness.start(deployment_str=deployment)

        self.provisioner_client = ProvisionerClient(self.dashi, topic='provisioner')
        self.epum_client = EPUManagementClient(self.dashi, topic='epum')
        self.dtrs_client = DTRSClient(self.dashi, topic='dtrs')

        self.phantom_url = "http://localhost:%s/" % phantom_port

        self.site_name = "site1"
        self.fake_site, self.driver = self.make_fake_libcloud_site(self.site_name)

        self.block_until_ready(deployment, self.dashi)

        self.load_dtrs()

    def load_dtrs(self):
        self.dtrs_client.add_dt(self.user, dt_name, example_dt)
        self.dtrs_client.add_site(self.site_name, self.fake_site)
        self.dtrs_client.add_credentials(self.user, self.site_name, fake_credentials)

    def xtest_example(self):
        # Place integration tests here!
        self.phantom_url