Example #1
0
    def test__cache_instance_images_master_path(self):
        temp_dir = tempfile.mkdtemp()
        self.config(images_path=temp_dir, group='pxe')
        self.config(instance_master_path=os.path.join(temp_dir,
                                                      'instance_master_path'),
                    group='pxe')
        fileutils.ensure_tree(CONF.pxe.instance_master_path)
        fd, tmp_master_image = tempfile.mkstemp(
            dir=CONF.pxe.instance_master_path)

        with mock.patch.object(images, 'fetch_to_raw') as fetch_to_raw_mock:
            with mock.patch.object(tempfile, 'mkstemp') as mkstemp_mock:
                with mock.patch.object(service_utils, 'parse_image_ref') \
                        as parse_image_ref_mock:
                    mkstemp_mock.return_value = (fd, tmp_master_image)
                    fetch_to_raw_mock.return_value = None
                    parse_image_ref_mock.return_value = ('image_uuid', None,
                                                         None, None)

                    (uuid,
                     image_path) = pxe._cache_instance_image(None, self.node)

                    mkstemp_mock.assert_called_once_with(
                        dir=CONF.pxe.instance_master_path)
                    fetch_to_raw_mock.assert_called_once_with(
                        None, 'glance://image_uuid', tmp_master_image, None)
                    parse_image_ref_mock.assert_called_once_with(
                        'glance://image_uuid')
                    self.assertEqual('glance://image_uuid', uuid)
                    self.assertEqual(
                        os.path.join(temp_dir, self.node.uuid, 'disk'),
                        image_path)
Example #2
0
 def test__cache_instance_images_master_path(self):
     temp_dir = tempfile.mkdtemp()
     CONF.set_default('images_path', temp_dir, group='pxe')
     CONF.set_default('instance_master_path',
                      os.path.join(temp_dir, 'instance_master_path'),
                      group='pxe')
     fileutils.ensure_tree(CONF.pxe.instance_master_path)
     fd, tmp_master_image = tempfile.mkstemp(
         dir=CONF.pxe.instance_master_path)
     self.mox.StubOutWithMock(images, 'fetch_to_raw')
     self.mox.StubOutWithMock(tempfile, 'mkstemp')
     self.mox.StubOutWithMock(service_utils, 'parse_image_ref')
     tempfile.mkstemp(dir=CONF.pxe.instance_master_path).\
         AndReturn((fd, tmp_master_image))
     images.fetch_to_raw(None, 'glance://image_uuid',
                         tmp_master_image,
                         None).\
         AndReturn(None)
     service_utils.parse_image_ref('glance://image_uuid').\
         AndReturn(('image_uuid', None, None, None))
     self.mox.ReplayAll()
     (uuid, image_path) = pxe._cache_instance_image(None, self.node)
     self.mox.VerifyAll()
     self.assertEqual(uuid, 'glance://image_uuid')
     self.assertEqual(image_path, temp_dir + '/fake_instance_name/disk')
Example #3
0
    def test__cache_instance_images_master_path(self):
        temp_dir = tempfile.mkdtemp()
        CONF.set_default('images_path', temp_dir, group='pxe')
        CONF.set_default('instance_master_path',
                         os.path.join(temp_dir, 'instance_master_path'),
                         group='pxe')
        fileutils.ensure_tree(CONF.pxe.instance_master_path)
        fd, tmp_master_image = tempfile.mkstemp(
            dir=CONF.pxe.instance_master_path)

        with mock.patch.object(images, 'fetch_to_raw') as fetch_to_raw_mock:
            with mock.patch.object(tempfile, 'mkstemp') as mkstemp_mock:
                with mock.patch.object(service_utils, 'parse_image_ref') \
                        as parse_image_ref_mock:
                    mkstemp_mock.return_value = (fd, tmp_master_image)
                    fetch_to_raw_mock.return_value = None
                    parse_image_ref_mock.return_value = ('image_uuid',
                                                         None,
                                                         None,
                                                         None)

                    (uuid, image_path) = pxe._cache_instance_image(None,
                                                                   self.node)

                    mkstemp_mock.assert_called_once_with(
                         dir=CONF.pxe.instance_master_path)
                    fetch_to_raw_mock.assert_called_once_with(None,
                                                       'glance://image_uuid',
                                                       tmp_master_image,
                                                       None)
                    parse_image_ref_mock.assert_called_once_with(
                                                       'glance://image_uuid')
                    self.assertEqual(uuid, 'glance://image_uuid')
                    self.assertEqual(
                            image_path, temp_dir + '/fake_instance_name/disk')
Example #4
0
    def test__cache_instance_images_master_path(self, mock_fetch_image):
        temp_dir = tempfile.mkdtemp()
        self.config(images_path=temp_dir, group="pxe")
        self.config(instance_master_path=os.path.join(temp_dir, "instance_master_path"), group="pxe")
        fileutils.ensure_tree(CONF.pxe.instance_master_path)

        (uuid, image_path) = pxe._cache_instance_image(None, self.node)
        mock_fetch_image.assert_called_once_with(None, mock.ANY, [(uuid, image_path)])
        self.assertEqual("glance://image_uuid", uuid)
        self.assertEqual(os.path.join(temp_dir, self.node.uuid, "disk"), image_path)
Example #5
0
    def test__cache_instance_images_no_master_path(self):
        temp_dir = tempfile.mkdtemp()
        self.config(images_path=temp_dir, group='pxe')
        self.config(instance_master_path=None, group='pxe')

        with mock.patch.object(images, 'fetch_to_raw') as fetch_to_raw_mock:
            fetch_to_raw_mock.return_value = None

            (uuid, image_path) = pxe._cache_instance_image(None, self.node)

            fetch_to_raw_mock.assert_called_once_with(
                None, 'glance://image_uuid',
                os.path.join(temp_dir, self.node.uuid, 'disk'), None)
            self.assertEqual('glance://image_uuid', uuid)
            self.assertEqual(os.path.join(temp_dir, self.node.uuid, 'disk'),
                             image_path)
Example #6
0
    def test__cache_instance_images_master_path(self, mock_fetch_image):
        temp_dir = tempfile.mkdtemp()
        self.config(images_path=temp_dir, group='pxe')
        self.config(instance_master_path=os.path.join(temp_dir,
                                                      'instance_master_path'),
                    group='pxe')
        fileutils.ensure_tree(CONF.pxe.instance_master_path)

        (uuid, image_path) = pxe._cache_instance_image(None,
                                                       self.node)
        mock_fetch_image.assert_called_once_with(uuid, image_path, ctx=None)
        self.assertEqual('glance://image_uuid', uuid)
        self.assertEqual(os.path.join(temp_dir,
                                      self.node.uuid,
                                      'disk'),
                         image_path)
Example #7
0
 def test__cache_instance_images_no_master_path(self):
     temp_dir = tempfile.mkdtemp()
     CONF.set_default('images_path', temp_dir, group='pxe')
     CONF.set_default('instance_master_path', None, group='pxe')
     self.mox.StubOutWithMock(images, 'fetch_to_raw')
     images.fetch_to_raw(None, 'glance://image_uuid',
                         os.path.join(temp_dir,
                                       'fake_instance_name/disk'),
                         None).AndReturn(None)
     self.mox.ReplayAll()
     (uuid, image_path) = pxe._cache_instance_image(None, self.node)
     self.mox.VerifyAll()
     self.assertEqual(uuid, 'glance://image_uuid')
     self.assertEqual(image_path,
                      os.path.join(temp_dir,
                                   'fake_instance_name/disk'))
Example #8
0
    def test__cache_instance_images_no_master_path(self):
        temp_dir = tempfile.mkdtemp()
        CONF.set_default('images_path', temp_dir, group='pxe')
        CONF.set_default('instance_master_path', None, group='pxe')

        with mock.patch.object(images, 'fetch_to_raw') as fetch_to_raw_mock:
            fetch_to_raw_mock.return_value = None

            (uuid, image_path) = pxe._cache_instance_image(None, self.node)

            fetch_to_raw_mock.assert_called_once_with(None,
                            'glance://image_uuid',
                            os.path.join(temp_dir, 'fake_instance_name/disk'),
                            None)
            self.assertEqual(uuid, 'glance://image_uuid')
            self.assertEqual(image_path,
                             os.path.join(temp_dir, 'fake_instance_name/disk'))
Example #9
0
    def test__cache_instance_images_no_master_path(self):
        temp_dir = tempfile.mkdtemp()
        self.config(images_path=temp_dir, group='pxe')
        self.config(instance_master_path=None, group='pxe')

        with mock.patch.object(images, 'fetch_to_raw') as fetch_to_raw_mock:
            fetch_to_raw_mock.return_value = None

            (uuid, image_path) = pxe._cache_instance_image(None, self.node)

            fetch_to_raw_mock.assert_called_once_with(None,
                            'glance://image_uuid',
                            os.path.join(temp_dir, self.node.uuid, 'disk'),
                            None)
            self.assertEqual('glance://image_uuid', uuid)
            self.assertEqual(os.path.join(temp_dir, self.node.uuid, 'disk'),
                             image_path)
Example #10
0
    def test__cache_instance_images_master_path(self, mock_fetch_image):
        temp_dir = tempfile.mkdtemp()
        self.config(images_path=temp_dir, group='pxe')
        self.config(instance_master_path=os.path.join(temp_dir,
                                                      'instance_master_path'),
                    group='pxe')
        fileutils.ensure_tree(CONF.pxe.instance_master_path)

        (uuid, image_path) = pxe._cache_instance_image(None,
                                                       self.node)
        mock_fetch_image.assert_called_once_with(None,
                                                 mock.ANY,
                                                 [(uuid, image_path)])
        self.assertEqual('glance://image_uuid', uuid)
        self.assertEqual(os.path.join(temp_dir,
                                      self.node.uuid,
                                      'disk'),
                         image_path)