Esempio n. 1
0
class TestGenerateUnitKeyAndMetadata(unittest.TestCase):
    def setUp(self):
        self.context = mock.MagicMock()
        self.context.config = test_config
        self.command = UploadOpenstackImageCommand(self.context)

    def test_with_cirros(self):
        unit_key, metadata = self.command.generate_unit_key_and_metadata(data.cirros_img_path)

        self.assertEqual(unit_key, {'image_checksum': '64d7c1cd2b6f60c92c14662941cb7913'})
        self.assertEqual(metadata, {'image_protected': True,
                                    'image_filename': 'cirros-0.3.2-x86_64-disk.img',
                                    'image_size': 13167616})

    def test_with_cirros_and_metadata(self):
        unit_key, metadata = self.command.generate_unit_key_and_metadata(data.cirros_img_path,
                                                                         image_min_ram=1024,
                                                                         image_name="fake name")

        self.assertEqual(unit_key, {'image_checksum': '64d7c1cd2b6f60c92c14662941cb7913'})
        self.assertEqual(metadata, {'image_protected': True, 'image_min_ram': 1024,
                                    'image_name': "fake name",
                                    'image_filename': 'cirros-0.3.2-x86_64-disk.img',
                                    'image_size': 13167616})

    def test_file_does_not_exist(self):
        self.assertRaises(IOError, self.command.generate_unit_key_and_metadata, '/a/b/c/d')
Esempio n. 2
0
class TestDetermineID(unittest.TestCase):
    def setUp(self):
        self.context = mock.MagicMock()
        self.context.config = test_config
        self.command = UploadOpenstackImageCommand(self.context)

    def test_return_value(self):
        ret = self.command.determine_type_id('/a/b/c')

        self.assertEqual(ret, constants.IMAGE_TYPE_ID)
Esempio n. 3
0
def add_upload_section(context, parent_section):
    """
    add an upload section to the openstack section

    :param context: pulp context
    :type  context: pulp.client.extensions.core.ClientContext
    :param parent_section:  section of the CLI to which the upload section
                            should be added
    :type  parent_section:  pulp.client.extensions.extensions.PulpCliSection
    :return: populated section
    :rtype: PulpCliSection
    """
    upload_section = parent_section.create_subsection(SECTION_UPLOADS,
                                                      DESC_UPLOADS)
    upload_section.add_command(UploadOpenstackImageCommand(context))

    return upload_section
Esempio n. 4
0
 def setUp(self):
     self.context = mock.MagicMock()
     self.context.config = test_config
     self.command = UploadOpenstackImageCommand(self.context)