Пример #1
0
    def test_properties_root_defice_name(self):
        mappings = [{"device": "/dev/sda1", "virtual": "root"}]
        properties0 = {"mappings": mappings}
        properties1 = {"root_device_name": "/dev/sdb", "mappings": mappings}

        root_device_name = block_device.properties_root_device_name(properties0)
        self.assertEqual(root_device_name, "/dev/sda1")

        root_device_name = block_device.properties_root_device_name(properties1)
        self.assertEqual(root_device_name, "/dev/sdb")
Пример #2
0
    def test_properties(self):
        root_device0 = "/dev/sda"
        root_device1 = "/dev/sdb"
        mappings = [{"virtual": "root", "device": root_device0}]

        properties0 = {"mappings": mappings}
        properties1 = {"mappings": mappings, "root_device_name": root_device1}

        self.assertIsNone(block_device.properties_root_device_name({}))
        self.assertEqual(block_device.properties_root_device_name(properties0), root_device0)
        self.assertEqual(block_device.properties_root_device_name(properties1), root_device1)
Пример #3
0
    def test_properties_root_defice_name(self):
        mappings = [{"device": "/dev/sda1", "virtual": "root"}]
        properties0 = {'mappings': mappings}
        properties1 = {'root_device_name': '/dev/sdb', 'mappings': mappings}

        root_device_name = block_device.properties_root_device_name(
            properties0)
        self.assertEqual(root_device_name, '/dev/sda1')

        root_device_name = block_device.properties_root_device_name(
            properties1)
        self.assertEqual(root_device_name, '/dev/sdb')
Пример #4
0
    def test_properties_root_defice_name(self):
        mappings = [{"device": "/dev/sda1", "virtual": "root"}]
        properties0 = {'mappings': mappings}
        properties1 = {'root_device_name': '/dev/sdb', 'mappings': mappings}

        root_device_name = block_device.properties_root_device_name(
            properties0)
        self.assertEqual(root_device_name, '/dev/sda1')

        root_device_name = block_device.properties_root_device_name(
            properties1)
        self.assertEqual(root_device_name, '/dev/sdb')
Пример #5
0
    def test_properties(self):
        root_device0 = '/dev/sda'
        root_device1 = '/dev/sdb'
        mappings = [{'virtual': 'root', 'device': root_device0}]

        properties0 = {'mappings': mappings}
        properties1 = {'mappings': mappings, 'root_device_name': root_device1}

        self.assertEqual(block_device.properties_root_device_name({}), None)
        self.assertEqual(block_device.properties_root_device_name(properties0),
                         root_device0)
        self.assertEqual(block_device.properties_root_device_name(properties1),
                         root_device1)
Пример #6
0
    def test_properties(self):
        root_device0 = '/dev/sda'
        root_device1 = '/dev/sdb'
        mappings = [{'virtual': 'root',
                     'device': root_device0}]

        properties0 = {'mappings': mappings}
        properties1 = {'mappings': mappings,
                       'root_device_name': root_device1}

        self.assertIsNone(block_device.properties_root_device_name({}))
        self.assertEqual(root_device0,
                         block_device.properties_root_device_name(properties0))
        self.assertEqual(root_device1,
                         block_device.properties_root_device_name(properties1))
Пример #7
0
    def apply(self, context, resource):

        if not resource.metadata:
            resource.metadata = {}
        if not resource.security_group:
            resource.security_group = 'default'

        if not resource.instance_type:
            resource.instance_type = instance_types.get_default_instance_type()
        if not resource.min_count:
            resource.min_count = 1
        if not resource.max_count:
            resource.max_count = resource.min_count

        resource.block_device_mapping = resource.block_device_mapping or []
        if resource.instance_type['disabled']:
            raise exception.InstanceTypeNotFound(
                    instance_type_id=resource.instance_type['id'])

        if resource.user_data:
            l = len(resource.user_data)
            if l > MAX_USERDATA_SIZE:
                # NOTE(mikal): user_data is stored in a text column, and
                # the database might silently truncate if its over length.
                raise exception.InstanceUserDataTooLarge(
                    length=l, maxsize=MAX_USERDATA_SIZE)

            try:
                base64.decodestring(resource.user_data)
            except base64.binascii.Error:
                raise exception.InstanceUserDataMalformed()

        # Reserve quotas
        resource.num_instances, resource.quota_reservations = \
                        self._check_num_instances_quota(context,
                                                        resource.instance_type,
                                                        resource.min_count,
                                                        resource.max_count)

        self._check_metadata_properties_quota(context, resource.metadata)
        self._check_injected_file_quota(context, resource.injected_files)
        self._check_requested_networks(context, resource.requested_networks)

        # Handle config_drive
        resource.config_drive_id = None
        if resource.config_drive and not utils.is_valid_boolstr(
                                                        resource.config_drive):
            # config_drive is volume id
            resource.config_drive_id = resource.config_drive
            resource.config_drive = None

            # Ensure config_drive image exists
            cd_image_service, config_drive_id = \
                      glance.get_remote_image_service(context,
                                                      resource.config_drive_id)
            cd_image_service.show(context, resource.config_drive_id)

        if resource.key_data is None and resource.key_name:
            resource.key_pair = self.db.key_pair_get(context, context.user_id,
                                            resource.key_name)
            resource.key_data = resource.key_pair['public_key']

        resource.root_device_name = block_device.properties_root_device_name(
                                          resource.image.get('properties', {}))

        resource.availability_zone, resource.forced_host = \
                     self._handle_availability_zone(resource.availability_zone)

        resource.system_metadata = instance_types.save_instance_type_info(
                                dict(), resource.instance_type)

        return orc_utils.DictableObject(details='request_validated',
                                        resource=resource)