コード例 #1
0
    def _dict_to_obj(cls, json_dict):
        """Override dict_to_obj implementation"""
        obj = cls._map_values_to_kwargs(json_dict)
        obj.fixed_ips = FixedIps._list_to_obj(obj.fixed_ips)
        obj.image_meta = ImageMeta._dict_to_obj(obj.image_meta)

        return obj
コード例 #2
0
    def _dict_to_obj(cls, json_dict):
        """Override dict_to_obj implementation"""
        obj = cls._map_values_to_kwargs(json_dict)
        obj.bandwidth = Bandwidth._dict_to_obj(obj.bandwidth)
        obj.image_meta = ImageMeta._dict_to_obj(obj.image_meta)

        return obj
コード例 #3
0
    def _dict_to_obj(cls, json_dict):
        """Override dict_to_obj implementation"""
        obj = cls._map_values_to_kwargs(json_dict)
        obj.exception = InstanceException._dict_to_obj(obj.exception)
        obj.image_meta = ImageMeta._dict_to_obj(obj.image_meta)

        return obj
コード例 #4
0
    def test_image_meta_extra_attribute_json(self):
        modified_dict = self.image_meta_dict.copy()
        modified_dict['test_dummy'] = 'test_dummy'

        actual_json = json.dumps(modified_dict)
        actual_obj = ImageMeta.deserialize(actual_json, 'json')
        self.assertIsNotNone(actual_obj)
コード例 #5
0
    def test_image_meta_missing_attribute_json(self):
        modified_dict = self.image_meta_dict.copy()
        modified_dict.pop('os_type')

        actual_json = json.dumps(modified_dict)
        actual_obj = ImageMeta.deserialize(actual_json, 'json')
        self.assertIsNone(actual_obj)
コード例 #6
0
    def test_image_meta_json(self):
        expected_obj = self.image_meta_obj

        actual_json = json.dumps(self.image_meta_dict)
        actual_obj = ImageMeta.deserialize(actual_json, 'json')

        self.assertEqual(expected_obj, actual_obj)
コード例 #7
0
    def setUpClass(cls):
        super(BaseCommonTest, cls).setUpClass()

        cls.bandwidth_interface_dict = {"bw_in": 123456, "bw_out": 654321}

        cls.bandwidth_dict = {
            "private": cls.bandwidth_interface_dict,
            "public": cls.bandwidth_interface_dict,
            "extra": cls.bandwidth_interface_dict
        }

        cls.fixed_ip_dict = {
            "address": "10.10.0.0",
            "floating_ips": [],
            "label": "public",
            "meta": {},
            "type": "fixed",
            "version": 4,
            "vif_mac": "FE:ED:FA:00:1C:D4"
        }

        cls.fixed_ips_dict = {"fixed_ips": [cls.fixed_ip_dict]}

        cls.image_meta_dict = {
            "auto_disk_config": "disabled",
            "base_image_ref": "5e91ad7f-afe4-4a83-bd5f-84673462cae1",
            "container_format": "ovf",
            "disk_format": "vhd",
            "image_type": "base",
            "min_disk": "20",
            "min_ram": "512",
            "org.openstack__1__architecture": "x64",
            "org.openstack__1__os_distro": "com.ubuntu",
            "org.openstack__1__os_version": "12.04",
            "os_type": "linux"
        }

        cls.instance_exception_dict = {
            "kwargs": {
                "instance_uuid": "5e91ad7f-afe4-4a83-bd5f-84673462cae1",
                "reason": "Something broke",
                "code": 500
            }
        }

        cls.bandwidth_obj = Bandwidth._dict_to_obj(cls.bandwidth_dict)
        cls.bandwidth_interface_obj = BandwidthInterface._dict_to_obj(
            cls.bandwidth_interface_dict)
        cls.fixed_ip_obj = FixedIp._dict_to_obj(cls.fixed_ip_dict)
        cls.fixed_ips_obj = FixedIps._list_to_obj(
            cls.fixed_ips_dict['fixed_ips'])
        cls.image_meta_obj = ImageMeta._dict_to_obj(cls.image_meta_dict)
        cls.instance_exception_obj = InstanceException._dict_to_obj(
            cls.instance_exception_dict)