Esempio n. 1
0
 def test_get_routing_keys_admin_no_clone_id(self):
     assert [
         "admin",
         "admin.system",
         "admin.system.1-0-0",
         "admin.system.1-0-0.instance",
     ] == get_routing_keys("system", "1.0.0", "instance", is_admin=True)
Esempio n. 2
0
    def initializeInstance(self, instance_id):
        """Initializes an instance.

        :param instance_id: The ID of the instance
        :return: QueueInformation object describing message queue for this system
        """
        instance = self._get_instance(instance_id)
        system = self._get_system(instance)

        self.logger.info(
            "Initializing instance %s[%s]-%s",
            system.name,
            instance.name,
            system.version,
        )

        routing_words = [system.name, system.version, instance.name]
        req_name = get_routing_key(*routing_words)
        req_args = {"durable": True, "arguments": {"x-max-priority": 1}}
        req_queue = self.clients["pika"].setup_queue(req_name, req_args,
                                                     [req_name])

        routing_words.append("".join(
            random.choice(string.ascii_lowercase + string.digits)
            for _ in range(10)))
        admin_keys = get_routing_keys(*routing_words, is_admin=True)
        admin_args = {"durable": True}
        admin_queue = self.clients["pika"].setup_queue(admin_keys[-1],
                                                       admin_args, admin_keys)

        connection = {
            "host": bartender.config.publish_hostname,
            "port": bartender.config.amq.connections.message.port,
            "user": bartender.config.amq.connections.message.user,
            "password": bartender.config.amq.connections.message.password,
            "virtual_host": bartender.config.amq.virtual_host,
            "ssl": {
                "enabled": bartender.config.amq.connections.message.ssl.enabled
            },
        }

        instance.status = "INITIALIZING"
        instance.status_info = StatusInfo(heartbeat=datetime.utcnow())
        instance.queue_type = "rabbitmq"
        instance.queue_info = {
            "admin": admin_queue,
            "request": req_queue,
            "connection": connection,
            "url": self.clients["public"].connection_url,
        }
        instance.save()

        # Send a request to start to the plugin on the plugin's admin queue
        self.clients["pika"].start(system=system.name,
                                   version=system.version,
                                   instance=instance.name)

        return self.parser.serialize_instance(instance, to_string=True)
Esempio n. 3
0
 def test_get_routing_keys_admin_clone_id(self):
     expected = [
         "admin",
         "admin.system",
         "admin.system.1-0-0",
         "admin.system.1-0-0.instance",
         "admin.system.1-0-0.instance.clone",
     ]
     assert expected == get_routing_keys(
         "system", "1.0.0", "instance", "clone", is_admin=True
     )
Esempio n. 4
0
 def test_get_routing_keys_admin_basic(self):
     assert ["admin"] == get_routing_keys(is_admin=True)
Esempio n. 5
0
 def test_get_routing_keys(self):
     assert ["system", "system.1-0-0", "system.1-0-0.instance"] == get_routing_keys(
         "system", "1.0.0", "instance"
     )