コード例 #1
0
    def test_restore(self):
        heat_template = HeatTemplate()
        resource = Resource(
            id="123",
            type=constants.VOLUME_RESOURCE_TYPE,
            name="fake",
        )
        checkpoint = self._get_checkpoint()
        section = checkpoint.get_resource_bank_section()
        section.update_object('metadata', {
            'backup_id': '456',
        })

        parameters = {
            "restore_name": "karbor restore volume",
            "restore_description": "karbor restore",
        }

        operation = self.plugin.get_restore_operation(resource)
        call_hooks(operation,
                   checkpoint,
                   resource,
                   self.cntxt,
                   parameters,
                   heat_template=heat_template)
        self.assertEqual(1, len(heat_template._resources))

        heat_resource_id = heat_template._original_id_resource_map["123"]
        template_dict = {
            "heat_template_version": str(datetime.date(2015, 10, 15)),
            "description": "karbor restore template",
            "resources": {
                heat_resource_id: {
                    "type": "OS::Cinder::Volume",
                    "properties": {
                        "description": "karbor restore",
                        "backup_id": "456",
                        "name": "karbor restore volume",
                    }
                }
            }
        }
        self.assertEqual(template_dict, heat_template.to_dict())
コード例 #2
0
    def test_restore_backup(self):
        heat_template = HeatTemplate()
        resource = Resource(id="123",
                            type=constants.VOLUME_RESOURCE_TYPE,
                            name="fake")
        resource_node = ResourceNode(value=resource,
                                     child_nodes=[])
        resource_definition = {"backup_id": "456"}
        kwargs = {"node": resource_node,
                  "heat_template": heat_template,
                  "restore_name": "karbor restore volume",
                  "restore_description": "karbor restore"}

        fake_bank_section.get_object = mock.MagicMock()
        fake_bank_section.get_object.return_value = resource_definition

        self.plugin.restore_backup(self.cntxt, self.checkpoint,
                                   **kwargs)
        self.assertEqual(1, len(heat_template._resources))

        heat_resource_id = heat_template._original_id_resource_map["123"]
        template_dict = {
            "heat_template_version": str(datetime.date(2015, 10, 15)),
            "description": "karbor restore template",
            "resources": {
                heat_resource_id: {
                    "type": "OS::Cinder::Volume",
                    "properties": {
                        "description": "karbor restore",
                        "backup_id": "456",
                        "name": "karbor restore volume",
                    }
                }
            }
        }
        self.assertEqual(template_dict, heat_template.to_dict())
コード例 #3
0
    def test_restore_backup(self):
        heat_template = HeatTemplate()
        resource = Resource(id="123",
                            type=constants.VOLUME_RESOURCE_TYPE,
                            name="fake")
        resource_node = ResourceNode(value=resource,
                                     child_nodes=[])
        resource_definition = {"backup_id": "456"}
        kwargs = {"node": resource_node,
                  "heat_template": heat_template,
                  "restore_name": "karbor restore volume",
                  "restore_description": "karbor restore"}

        fake_bank_section.get_object = mock.MagicMock()
        fake_bank_section.get_object.return_value = resource_definition

        self.plugin.restore_backup(self.cntxt, self.checkpoint,
                                   **kwargs)
        self.assertEqual(1, len(heat_template._resources))

        heat_resource_id = heat_template._original_id_resource_map["123"]
        template_dict = {
            "heat_template_version": str(datetime.date(2015, 10, 15)),
            "description": "karbor restore template",
            "resources": {
                heat_resource_id: {
                    "type": "OS::Cinder::Volume",
                    "properties": {
                        "description": "karbor restore",
                        "backup_id": "456",
                        "name": "karbor restore volume",
                    }
                }
            }
        }
        self.assertEqual(template_dict, heat_template.to_dict())
コード例 #4
0
class HeatTemplateTest(base.TestCase):
    def setUp(self):
        super(HeatTemplateTest, self).setUp()
        self.heat_template = HeatTemplate()

    def test_put_resource(self):
        fake_original_id = "123456"
        fake_resource_id = "restore_123456"
        fake_resource_type = "OS::Cinder::Volume"
        heat_resource = HeatResource(fake_resource_id, fake_resource_type)
        properties = {
            "volume_type": "lvmdriver-1",
            "size": 1
        }
        for key, value in properties.items():
            heat_resource.set_property(key, value)
        self.heat_template.put_resource(fake_original_id, heat_resource)
        self.assertEqual(1, len(self.heat_template._resources))
        self.assertEqual(
            fake_resource_id,
            self.heat_template._original_id_resource_map[fake_original_id]
        )

    def test_put_parameter(self):
        fake_original_id = "123456"
        fake_parameter = "restored_123456"
        self.heat_template.put_parameter(fake_original_id, fake_parameter)
        self.assertEqual(1, len(self.heat_template._original_id_parameter_map))
        self.assertEqual(
            fake_parameter,
            self.heat_template._original_id_parameter_map[fake_original_id]
        )

    def test_get_resource_reference(self):
        fake_original_id = "123456"
        fake_resource_id = "restore_123456"
        fake_resource_type = "OS::Cinder::Volume"
        heat_resource = HeatResource(fake_resource_id, fake_resource_type)
        properties = {
            "volume_type": "lvmdriver-1",
            "size": 1
        }
        for key, value in properties.items():
            heat_resource.set_property(key, value)
        self.heat_template.put_resource(fake_original_id, heat_resource)

        reference = self.heat_template.get_resource_reference(fake_original_id)
        self.assertEqual({"get_resource": "restore_123456"}, reference)

        fake_original_id = '23456'
        fake_parameter = 'restored_23456'
        self.heat_template.put_parameter(fake_original_id, fake_parameter)
        reference = self.heat_template.get_resource_reference(fake_original_id)
        self.assertEqual(fake_parameter, reference)

    def test_to_dict(self):
        fake_original_id = "123456"
        fake_resource_id = "restore_123456"
        fake_resource_type = "OS::Cinder::Volume"
        heat_resource = HeatResource(fake_resource_id, fake_resource_type)
        properties = {
            "volume_type": "lvmdriver-1",
            "size": 1
        }
        for key, value in properties.items():
            heat_resource.set_property(key, value)
        self.heat_template.put_resource(fake_original_id, heat_resource)

        fake_original_id_2 = '23456'
        fake_parameter = 'restored_23456'
        self.heat_template.put_parameter(fake_original_id_2, fake_parameter)

        template_dict = self.heat_template.to_dict()

        target_dict = {
            "heat_template_version": str(datetime.date(2015, 10, 15)),
            "description": "karbor restore template",
            "resources": {
                "restore_123456": {
                    "type": "OS::Cinder::Volume",
                    "properties": {
                        "volume_type": "lvmdriver-1",
                        "size": 1
                    }
                }
            }
        }
        self.assertEqual(target_dict, template_dict)

    def test_dump_to_yaml_file(self):
        fake_original_id = "123456"
        temp_dir = tempfile.mkdtemp()
        temp_file = temp_dir + "/template.yaml"

        fake_resource_id = "restore_123456"
        fake_resource_type = "OS::Cinder::Volume"
        heat_resource = HeatResource(fake_resource_id, fake_resource_type)
        properties = {
            "volume_type": "lvmdriver-1",
            "size": 1
        }
        for key, value in properties.items():
            heat_resource.set_property(key, value)
        self.heat_template.put_resource(fake_original_id, heat_resource)

        self.heat_template.dump_to_yaml_file(temp_file)

        with open(temp_file, "r") as f:
            template_dict = yaml.load(f)
        target_dict = {
            "heat_template_version": str(datetime.date(2015, 10, 15)),
            "description": "karbor restore template",
            "resources": {
                "restore_123456": {
                    "type": "OS::Cinder::Volume",
                    "properties": {
                        "volume_type": "lvmdriver-1",
                        "size": 1
                    }
                }
            }
        }
        self.assertEqual(target_dict, template_dict)