Ejemplo n.º 1
0
 def test_heat_template_load_success(self):
     mysql_tmpl = template.load_heat_template('mysql')
     #TODO(denis_makogon): use it when redis template would be added
     #redis_tmplt = template.load_heat_template('redis')
     cassandra_tmpl = template.load_heat_template('cassandra')
     mongo_tmpl = template.load_heat_template('mongodb')
     self.assertIsNotNone(mysql_tmpl)
     self.assertIsNotNone(cassandra_tmpl)
     self.assertIsNotNone(mongo_tmpl)
Ejemplo n.º 2
0
 def test_heat_template_load_success(self):
     mysql_tmpl = template.load_heat_template('mysql')
     redis_tmplt = template.load_heat_template('redis')
     cassandra_tmpl = template.load_heat_template('cassandra')
     mongo_tmpl = template.load_heat_template('mongodb')
     self.assertIsNotNone(mysql_tmpl)
     self.assertIsNotNone(redis_tmplt)
     self.assertIsNotNone(cassandra_tmpl)
     self.assertIsNotNone(mongo_tmpl)
Ejemplo n.º 3
0
 def test_heat_template_load_success(self):
     mysql_tmpl = template.load_heat_template('mysql')
     #TODO(denis_makogon): use it when redis template would be added
     #redis_tmplt = template.load_heat_template('redis')
     cassandra_tmpl = template.load_heat_template('cassandra')
     mongo_tmpl = template.load_heat_template('mongodb')
     self.assertIsNotNone(mysql_tmpl)
     self.assertIsNotNone(cassandra_tmpl)
     self.assertIsNotNone(mongo_tmpl)
Ejemplo n.º 4
0
 def test_heat_template_load_success(self):
     mysql_tmpl = template.load_heat_template('mysql')
     redis_tmplt = template.load_heat_template('redis')
     cassandra_tmpl = template.load_heat_template('cassandra')
     mongo_tmpl = template.load_heat_template('mongodb')
     self.assertIsNotNone(mysql_tmpl)
     self.assertIsNotNone(redis_tmplt)
     self.assertIsNotNone(cassandra_tmpl)
     self.assertIsNotNone(mongo_tmpl)
Ejemplo n.º 5
0
 def test_no_rules_if_no_ports(self):
     mysql_tmpl = template.load_heat_template('mysql')
     output = mysql_tmpl.render(
         volume_support=True,
         ifaces=[], ports=[],
         tcp_rules=[],
         udp_rules=[])
     self.assertIsNotNone(output)
     self.assertNotIn('- IpProtocol: "tcp"', output)
     self.assertNotIn('- IpProtocol: "udp"', output)
Ejemplo n.º 6
0
 def test_no_rules_if_no_ports(self):
     mysql_tmpl = template.load_heat_template('mysql')
     output = mysql_tmpl.render(volume_support=True,
                                ifaces=[],
                                ports=[],
                                tcp_rules=[],
                                udp_rules=[])
     self.assertIsNotNone(output)
     self.assertNotIn('- IpProtocol: "tcp"', output)
     self.assertNotIn('- IpProtocol: "udp"', output)
Ejemplo n.º 7
0
    def _create_server_volume_heat(self, flavor, image_id,
                                   datastore_manager,
                                   volume_size, availability_zone):
        LOG.debug(_("begin _create_server_volume_heat for id: %s") % self.id)
        client = create_heat_client(self.context)
        novaclient = create_nova_client(self.context)

        template_obj = template.load_heat_template(datastore_manager)
        heat_template_unicode = template_obj.render()
        try:
            heat_template = heat_template_unicode.encode('ascii')
        except UnicodeEncodeError:
            LOG.error(_("heat template ascii encode issue"))
            raise TroveError("heat template ascii encode issue")

        parameters = {"Flavor": flavor["name"],
                      "VolumeSize": volume_size,
                      "InstanceId": self.id,
                      "ImageId": image_id,
                      "DatastoreManager": datastore_manager,
                      "AvailabilityZone": availability_zone}
        stack_name = 'trove-%s' % self.id
        client.stacks.create(stack_name=stack_name,
                             template=heat_template,
                             parameters=parameters)
        stack = client.stacks.get(stack_name)

        utils.poll_until(
            lambda: client.stacks.get(stack_name),
            lambda stack: stack.stack_status in ['CREATE_COMPLETE',
                                                 'CREATE_FAILED'],
            sleep_time=2,
            time_out=HEAT_TIME_OUT)

        resource = client.resources.get(stack.id, 'BaseInstance')
        server = novaclient.servers.get(resource.physical_resource_id)

        if CONF.trove_volume_support:
            cinderclient = create_cinder_client(self.context)
            resource = client.resources.get(stack.id, 'DataVolume')
            volume = cinderclient.volumes.get(resource.physical_resource_id)
            volume_info = self._build_volume(volume)
            self.update_db(compute_instance_id=server.id, volume_id=volume.id)
        else:
            volume_info = self._build_volume_info(volume_size)
            self.update_db(compute_instance_id=server.id)

        LOG.debug(_("end _create_server_volume_heat for id: %s") % self.id)
        return server, volume_info
Ejemplo n.º 8
0
 def test_render_templates_with_ports_from_config(self):
     mysql_tmpl = template.load_heat_template("mysql")
     tcp_rules = [
         {"cidr": "0.0.0.0/0", "from_": 3306, "to_": 3309},
         {"cidr": "0.0.0.0/0", "from_": 3320, "to_": 33022},
     ]
     output = mysql_tmpl.render(
         volume_support=True, ifaces=[], ports=[], tcp_rules=tcp_rules, udp_rules=[], files={}
     )
     self.assertIsNotNone(output)
     self.assertIn('FromPort: "3306"', output)
     self.assertIn('ToPort: "3309"', output)
     self.assertIn('CidrIp: "0.0.0.0/0"', output)
     self.assertIn('FromPort: "3320"', output)
     self.assertIn('ToPort: "33022"', output)
Ejemplo n.º 9
0
    def _create_server_volume_heat(self, flavor, image_id, datastore_manager,
                                   volume_size, availability_zone):
        LOG.debug(_("begin _create_server_volume_heat for id: %s") % self.id)
        client = create_heat_client(self.context)
        novaclient = create_nova_client(self.context)
        cinderclient = create_cinder_client(self.context)

        template_obj = template.load_heat_template(datastore_manager)
        heat_template_unicode = template_obj.render()
        try:
            heat_template = heat_template_unicode.encode('ascii')
        except UnicodeEncodeError:
            LOG.error(_("heat template ascii encode issue"))
            raise TroveError("heat template ascii encode issue")

        parameters = {
            "Flavor": flavor["name"],
            "VolumeSize": volume_size,
            "InstanceId": self.id,
            "ImageId": image_id,
            "DatastoreManager": datastore_manager,
            "AvailabilityZone": availability_zone
        }
        stack_name = 'trove-%s' % self.id
        client.stacks.create(stack_name=stack_name,
                             template=heat_template,
                             parameters=parameters)
        stack = client.stacks.get(stack_name)

        utils.poll_until(lambda: client.stacks.get(stack_name),
                         lambda stack: stack.stack_status in
                         ['CREATE_COMPLETE', 'CREATE_FAILED'],
                         sleep_time=2,
                         time_out=HEAT_TIME_OUT)

        resource = client.resources.get(stack.id, 'BaseInstance')
        server = novaclient.servers.get(resource.physical_resource_id)

        resource = client.resources.get(stack.id, 'DataVolume')
        volume = cinderclient.volumes.get(resource.physical_resource_id)
        volume_info = self._build_volume(volume)

        self.update_db(compute_instance_id=server.id, volume_id=volume.id)
        LOG.debug(_("end _create_server_volume_heat for id: %s") % self.id)
        return server, volume_info
Ejemplo n.º 10
0
 def test_render_templates_with_ports_from_config(self):
     mysql_tmpl = template.load_heat_template('mysql')
     tcp_rules = [{'cidr': "0.0.0.0/0",
                   'from_': 3306,
                   'to_': 3309},
                  {'cidr': "0.0.0.0/0",
                   'from_': 3320,
                   'to_': 33022}]
     output = mysql_tmpl.render(
         volume_support=True,
         ifaces=[], ports=[],
         tcp_rules=tcp_rules,
         udp_rules=[])
     self.assertIsNotNone(output)
     self.assertIn('FromPort: "3306"', output)
     self.assertIn('ToPort: "3309"', output)
     self.assertIn('CidrIp: "0.0.0.0/0"', output)
     self.assertIn('FromPort: "3320"', output)
     self.assertIn('ToPort: "33022"', output)
Ejemplo n.º 11
0
 def test_render_templates_with_ports_from_config(self):
     mysql_tmpl = template.load_heat_template('mysql')
     tcp_rules = [{'cidr': "0.0.0.0/0",
                   'from_': 3306,
                   'to_': 3309},
                  {'cidr': "0.0.0.0/0",
                   'from_': 3320,
                   'to_': 33022}]
     output = mysql_tmpl.render(
         volume_support=True,
         ifaces=[], ports=[],
         tcp_rules=tcp_rules,
         udp_rules=[])
     self.assertIsNotNone(output)
     self.assertIn('FromPort: "3306"', output)
     self.assertIn('ToPort: "3309"', output)
     self.assertIn('CidrIp: "0.0.0.0/0"', output)
     self.assertIn('FromPort: "3320"', output)
     self.assertIn('ToPort: "33022"', output)
Ejemplo n.º 12
0
 def test_heat_template_load_success(self):
     mysql_tmpl = template.load_heat_template('mysql')
     redis_tmpl = template.load_heat_template('redis')
     cassandra_tmpl = template.load_heat_template('cassandra')
     mongo_tmpl = template.load_heat_template('mongodb')
     percona_tmpl = template.load_heat_template('percona')
     couchbase_tmpl = template.load_heat_template('couchbase')
     self.assertIsNotNone(mysql_tmpl)
     self.assertIsNotNone(redis_tmpl)
     self.assertIsNotNone(cassandra_tmpl)
     self.assertIsNotNone(mongo_tmpl)
     self.assertIsNotNone(percona_tmpl)
     self.assertIsNotNone(couchbase_tmpl)
     self.assertEqual(self.default, mysql_tmpl.name)
     self.assertEqual(self.default, redis_tmpl.name)
     self.assertEqual(self.default, cassandra_tmpl.name)
     self.assertEqual(self.default, mongo_tmpl.name)
     self.assertEqual(self.default, percona_tmpl.name)
     self.assertEqual(self.default, couchbase_tmpl.name)
Ejemplo n.º 13
0
 def test_heat_template_load_success(self):
     mysql_tmpl = template.load_heat_template('mysql')
     redis_tmpl = template.load_heat_template('redis')
     cassandra_tmpl = template.load_heat_template('cassandra')
     mongo_tmpl = template.load_heat_template('mongodb')
     percona_tmpl = template.load_heat_template('percona')
     couchbase_tmpl = template.load_heat_template('couchbase')
     self.assertIsNotNone(mysql_tmpl)
     self.assertIsNotNone(redis_tmpl)
     self.assertIsNotNone(cassandra_tmpl)
     self.assertIsNotNone(mongo_tmpl)
     self.assertIsNotNone(percona_tmpl)
     self.assertIsNotNone(couchbase_tmpl)
     self.assertEqual(self.default, mysql_tmpl.name)
     self.assertEqual(self.default, redis_tmpl.name)
     self.assertEqual(self.default, cassandra_tmpl.name)
     self.assertEqual(self.default, mongo_tmpl.name)
     self.assertEqual(self.default, percona_tmpl.name)
     self.assertEqual(self.default, couchbase_tmpl.name)
Ejemplo n.º 14
0
 def test_heat_template_load_success(self):
     mysql_tmpl = template.load_heat_template("mysql")
     redis_tmpl = template.load_heat_template("redis")
     cassandra_tmpl = template.load_heat_template("cassandra")
     mongo_tmpl = template.load_heat_template("mongodb")
     percona_tmpl = template.load_heat_template("percona")
     couchbase_tmpl = template.load_heat_template("couchbase")
     self.assertIsNotNone(mysql_tmpl)
     self.assertIsNotNone(redis_tmpl)
     self.assertIsNotNone(cassandra_tmpl)
     self.assertIsNotNone(mongo_tmpl)
     self.assertIsNotNone(percona_tmpl)
     self.assertIsNotNone(couchbase_tmpl)
     self.assertEqual(self.default, mysql_tmpl.name)
     self.assertEqual(self.default, redis_tmpl.name)
     self.assertEqual(self.default, cassandra_tmpl.name)
     self.assertEqual(self.default, mongo_tmpl.name)
     self.assertEqual(self.default, percona_tmpl.name)
     self.assertEqual(self.default, couchbase_tmpl.name)
Ejemplo n.º 15
0
 def test_heat_template_load_success(self):
     mysql_tmpl = template.load_heat_template('mysql')
     cassandra_tmpl = template.load_heat_template('cassandra')
     self.assertIsNotNone(mysql_tmpl)
     self.assertIsNotNone(cassandra_tmpl)
Ejemplo n.º 16
0
 def test_heat_template_load_non_default(self):
     orig = utils.ENV._load_template
     utils.ENV._load_template = Mock(return_value=self.FakeTemplate())
     mysql_tmpl = template.load_heat_template('mysql')
     self.assertNotEqual(mysql_tmpl.name, self.default)
     utils.ENV._load_template = orig
Ejemplo n.º 17
0
 def test_heat_template_load_success(self):
     htmpl = template.load_heat_template('mysql')
     self.assertNotEqual(None, htmpl)
Ejemplo n.º 18
0
 def test_heat_template_load_non_default(self):
     orig = utils.ENV._load_template
     utils.ENV._load_template = Mock(return_value=self.FakeTemplate())
     mysql_tmpl = template.load_heat_template('mysql')
     self.assertNotEqual(mysql_tmpl.name, self.default)
     utils.ENV._load_template = orig
Ejemplo n.º 19
0
 def test_heat_template_load_success(self):
     mysql_tmpl = template.load_heat_template('mysql')
     cassandra_tmpl = template.load_heat_template('cassandra')
     self.assertIsNotNone(mysql_tmpl)
     self.assertIsNotNone(cassandra_tmpl)
Ejemplo n.º 20
0
 def test_heat_template_load_success(self):
     htmpl = template.load_heat_template('mysql')
     self.assertNotEqual(None, htmpl)
Ejemplo n.º 21
0
    def _create_server_volume_heat(self, flavor, image_id,
                                   datastore_manager,
                                   volume_size, availability_zone):
        LOG.debug(_("begin _create_server_volume_heat for id: %s") % self.id)
        try:
            client = create_heat_client(self.context)

            template_obj = template.load_heat_template(datastore_manager)
            heat_template_unicode = template_obj.render(
                volume_support=CONF.trove_volume_support)
            try:
                heat_template = heat_template_unicode.encode('utf-8')
            except UnicodeEncodeError:
                LOG.error(_("heat template ascii encode issue"))
                raise TroveError("heat template ascii encode issue")

            parameters = {"Flavor": flavor["name"],
                          "VolumeSize": volume_size,
                          "InstanceId": self.id,
                          "ImageId": image_id,
                          "DatastoreManager": datastore_manager,
                          "AvailabilityZone": availability_zone,
                          "TenantId": self.tenant_id}
            stack_name = 'trove-%s' % self.id
            client.stacks.create(stack_name=stack_name,
                                 template=heat_template,
                                 parameters=parameters)
            stack = client.stacks.get(stack_name)
            try:
                utils.poll_until(
                    lambda: client.stacks.get(stack_name),
                    lambda stack: stack.stack_status in ['CREATE_COMPLETE',
                                                         'CREATE_FAILED'],
                    sleep_time=USAGE_SLEEP_TIME,
                    time_out=HEAT_TIME_OUT)
            except PollTimeOut:
                LOG.error(_("Timeout during stack status tracing"))
                raise TroveError("Timeout occured in tracking stack status")

            stack = client.stacks.get(stack_name)
            if ((stack.action, stack.stack_status)
                    not in HEAT_STACK_SUCCESSFUL_STATUSES):
                raise TroveError("Heat Stack Create Failed.")

            resource = client.resources.get(stack.id, 'BaseInstance')
            if resource.state not in HEAT_RESOURCE_SUCCESSFUL_STATES:
                raise TroveError("Heat Resource Provisioning Failed.")
            instance_id = resource.physical_resource_id

            if CONF.trove_volume_support:
                resource = client.resources.get(stack.id, 'DataVolume')
                if resource.state not in HEAT_RESOURCE_SUCCESSFUL_STATES:
                    raise TroveError("Heat Resource Provisioning Failed.")
                volume_id = resource.physical_resource_id
                self.update_db(compute_instance_id=instance_id,
                               volume_id=volume_id)
            else:
                self.update_db(compute_instance_id=instance_id)

        except (TroveError, heat_exceptions.HTTPNotFound) as e:
            msg = _("Error during creating stack for instance %s") % self.id
            LOG.debug(msg)
            err = inst_models.InstanceTasks.BUILDING_ERROR_SERVER
            self._log_and_raise(e, msg, err)

        device_path = CONF.device_path
        mount_point = CONF.mount_point
        volume_info = {'device_path': device_path, 'mount_point': mount_point}

        LOG.debug(_("end _create_server_volume_heat for id: %s") % self.id)
        return volume_info