os-xenapi: fix tempest test error from glance

The image_id argument is not used anymore, but I still passed it
to `_update_image_meta_v2` function, which lead to a tempest test
error. This patch is used to fix this error.
Modify the unit test to prevent similar issues.

Change-Id: I8cb9f6bd31f2f3ac2e4688253aee255b774f1b69
This commit is contained in:
naichuans
2017-09-11 03:12:37 +00:00
parent ca0d98297d
commit 4056689f0b
2 changed files with 85 additions and 27 deletions

View File

@@ -370,8 +370,7 @@ def _upload_tarball_by_url_v2(staging_path, image_id, glance_endpoint,
mgt_parts = urlparse(mgt_url) mgt_parts = urlparse(mgt_url)
mgt_path = mgt_parts[2] mgt_path = mgt_parts[2]
_update_image_meta_v2(conn, image_id, extra_headers, properties, _update_image_meta_v2(conn, extra_headers, properties, mgt_path)
mgt_path)
validate_image_status_before_upload_v2(conn, url, extra_headers, validate_image_status_before_upload_v2(conn, url, extra_headers,
mgt_path) mgt_path)

View File

@@ -330,21 +330,34 @@ class GlanceTestCase(plugin_test.PluginTestBase):
fake_extra_headers = {} fake_extra_headers = {}
fake_properties = {} fake_properties = {}
fake_endpoint = 'http://fake_netloc/fake_path' fake_endpoint = 'http://fake_netloc/fake_path'
fake_image_id = 'fake_image_id'
expected_url = "%(glance_endpoint)s/v2/images/%(image_id)s/file" % { expected_url = "%(glance_endpoint)s/v2/images/%(image_id)s/file" % {
'glance_endpoint': fake_endpoint, 'glance_endpoint': fake_endpoint,
'image_id': 'fake_image_id'} 'image_id': fake_image_id}
expected_wsgi_path = '/fake_path/v2/images/%s' % 'fake_image_id' expected_wsgi_path = '/fake_path/v2/images/%s' % fake_image_id
expect_url_parts = urlparse(expected_url)
expected_mgt_url = "%(glance_endpoint)s/v2/images/%(image_id)s" % {
'glance_endpoint': fake_endpoint,
'image_id': fake_image_id}
fake_mgt_parts = urlparse(expected_mgt_url)
fake_mgt_path = fake_mgt_parts[2]
self.glance._upload_tarball_by_url_v2( self.glance._upload_tarball_by_url_v2(
'fake_staging_path', 'fake_image_id', fake_endpoint, 'fake_staging_path', fake_image_id, fake_endpoint,
fake_extra_headers, fake_properties) fake_extra_headers, fake_properties)
self.assertTrue(mock_HTTPConn.called) mock_HTTPConn.assert_called_with(expect_url_parts[0],
expect_url_parts[1])
mock_validate_image.assert_called_with(fake_conn, mock_validate_image.assert_called_with(fake_conn,
expected_url, expected_url,
fake_extra_headers, fake_extra_headers,
expected_wsgi_path) expected_wsgi_path)
self.assertTrue(mock_update_image_meta.called) mock_update_image_meta.assert_called_with(fake_conn,
fake_extra_headers,
fake_properties,
fake_mgt_path)
self.assertTrue(mock_create_tarball.called) self.assertTrue(mock_create_tarball.called)
self.assertTrue( self.assertTrue(
mock_HTTPConn.return_value.getresponse.called) mock_HTTPConn.return_value.getresponse.called)
@@ -368,17 +381,29 @@ class GlanceTestCase(plugin_test.PluginTestBase):
fake_extra_headers = {} fake_extra_headers = {}
fake_properties = {} fake_properties = {}
fake_endpoint = 'https://fake_netloc/fake_path' fake_endpoint = 'https://fake_netloc/fake_path'
fake_image_id = 'fake_image_id'
expected_url = "%(glance_endpoint)s/v2/images/%(image_id)s/file" % { expected_url = "%(glance_endpoint)s/v2/images/%(image_id)s/file" % {
'glance_endpoint': fake_endpoint, 'glance_endpoint': fake_endpoint,
'image_id': 'fake_image_id'} 'image_id': fake_image_id}
expected_wsgi_path = '/fake_path/v2/images/%s' % 'fake_image_id' expect_url_parts = urlparse(expected_url)
expected_wsgi_path = '/fake_path/v2/images/%s' % fake_image_id
expected_mgt_url = "%(glance_endpoint)s/v2/images/%(image_id)s" % {
'glance_endpoint': fake_endpoint,
'image_id': fake_image_id}
fake_mgt_parts = urlparse(expected_mgt_url)
fake_mgt_path = fake_mgt_parts[2]
self.glance._upload_tarball_by_url_v2( self.glance._upload_tarball_by_url_v2(
'fake_staging_path', 'fake_image_id', fake_endpoint, 'fake_staging_path', fake_image_id, fake_endpoint,
fake_extra_headers, fake_properties) fake_extra_headers, fake_properties)
self.assertTrue(mock_HTTPSConn.called) mock_update_image_meta.assert_called_with(fake_conn,
self.assertTrue(mock_update_image_meta.called) fake_extra_headers,
fake_properties,
fake_mgt_path)
mock_HTTPSConn.assert_called_with(expect_url_parts[0],
expect_url_parts[1])
mock_validate_image.assert_called_with(fake_conn, mock_validate_image.assert_called_with(fake_conn,
expected_url, expected_url,
fake_extra_headers, fake_extra_headers,
@@ -406,17 +431,28 @@ class GlanceTestCase(plugin_test.PluginTestBase):
fake_extra_headers = {} fake_extra_headers = {}
fake_properties = {} fake_properties = {}
fake_endpoint = 'https://fake_netloc:fake_port' fake_endpoint = 'https://fake_netloc:fake_port'
fake_image_id = 'fake_image_id'
expected_url = "%(glance_endpoint)s/v2/images/%(image_id)s/file" % { expected_url = "%(glance_endpoint)s/v2/images/%(image_id)s/file" % {
'glance_endpoint': fake_endpoint, 'glance_endpoint': fake_endpoint,
'image_id': 'fake_image_id'} 'image_id': fake_image_id}
expected_api_path = '/v2/images/%s' % 'fake_image_id' expect_url_parts = urlparse(expected_url)
expected_api_path = '/v2/images/%s' % fake_image_id
expected_mgt_url = "%(glance_endpoint)s/v2/images/%(image_id)s" % {
'glance_endpoint': fake_endpoint,
'image_id': fake_image_id}
fake_mgt_parts = urlparse(expected_mgt_url)
fake_mgt_path = fake_mgt_parts[2]
self.glance._upload_tarball_by_url_v2( self.glance._upload_tarball_by_url_v2(
'fake_staging_path', 'fake_image_id', fake_endpoint, 'fake_staging_path', fake_image_id, fake_endpoint,
fake_extra_headers, fake_properties) fake_extra_headers, fake_properties)
self.assertTrue(mock_Conn.called) mock_update_image_meta.assert_called_with(fake_conn,
self.assertTrue(mock_update_image_meta.called) fake_extra_headers,
fake_properties,
fake_mgt_path)
mock_Conn.assert_called_with(expect_url_parts[0], expect_url_parts[1])
mock_validate_image.assert_called_with(fake_conn, mock_validate_image.assert_called_with(fake_conn,
expected_url, expected_url,
fake_extra_headers, fake_extra_headers,
@@ -444,17 +480,28 @@ class GlanceTestCase(plugin_test.PluginTestBase):
fake_extra_headers = {} fake_extra_headers = {}
fake_properties = {} fake_properties = {}
fake_endpoint = 'https://fake_netloc/fake_path' fake_endpoint = 'https://fake_netloc/fake_path'
fake_image_id = 'fake_image_id'
expected_url = "%(glance_endpoint)s/v2/images/%(image_id)s/file" % { expected_url = "%(glance_endpoint)s/v2/images/%(image_id)s/file" % {
'glance_endpoint': fake_endpoint, 'glance_endpoint': fake_endpoint,
'image_id': 'fake_image_id'} 'image_id': fake_image_id}
expected_wsgi_path = '/fake_path/v2/images/%s' % 'fake_image_id' expect_url_parts = urlparse(expected_url)
expected_wsgi_path = '/fake_path/v2/images/%s' % fake_image_id
expected_mgt_url = "%(glance_endpoint)s/v2/images/%(image_id)s" % {
'glance_endpoint': fake_endpoint,
'image_id': fake_image_id}
fake_mgt_parts = urlparse(expected_mgt_url)
fake_mgt_path = fake_mgt_parts[2]
self.glance._upload_tarball_by_url_v2( self.glance._upload_tarball_by_url_v2(
'fake_staging_path', 'fake_image_id', fake_endpoint, 'fake_staging_path', fake_image_id, fake_endpoint,
fake_extra_headers, fake_properties) fake_extra_headers, fake_properties)
self.assertTrue(mock_Conn.called) mock_update_image_meta.assert_called_with(fake_conn,
self.assertTrue(mock_update_image_meta.called) fake_extra_headers,
fake_properties,
fake_mgt_path)
mock_Conn.assert_called_with(expect_url_parts[0], expect_url_parts[1])
mock_validate_image.assert_called_with(fake_conn, mock_validate_image.assert_called_with(fake_conn,
expected_url, expected_url,
fake_extra_headers, fake_extra_headers,
@@ -482,17 +529,29 @@ class GlanceTestCase(plugin_test.PluginTestBase):
fake_extra_headers = {} fake_extra_headers = {}
fake_properties = {} fake_properties = {}
fake_endpoint = 'https://fake_netloc/fake_path' fake_endpoint = 'https://fake_netloc/fake_path'
fake_image_id = 'fake_image_id'
expected_url = "%(glance_endpoint)s/v2/images/%(image_id)s/file" % { expected_url = "%(glance_endpoint)s/v2/images/%(image_id)s/file" % {
'glance_endpoint': fake_endpoint, 'glance_endpoint': fake_endpoint,
'image_id': 'fake_image_id'} 'image_id': fake_image_id}
expected_wsgi_path = '/fake_path/v2/images/%s' % 'fake_image_id' expected_wsgi_path = '/fake_path/v2/images/%s' % fake_image_id
expected_mgt_url = "%(glance_endpoint)s/v2/images/%(image_id)s" % {
'glance_endpoint': fake_endpoint,
'image_id': fake_image_id}
expect_url_parts = urlparse(expected_url)
fake_mgt_parts = urlparse(expected_mgt_url)
fake_mgt_path = fake_mgt_parts[2]
self.glance._upload_tarball_by_url_v2( self.glance._upload_tarball_by_url_v2(
'fake_staging_path', 'fake_image_id', fake_endpoint, 'fake_staging_path', fake_image_id, fake_endpoint,
fake_extra_headers, fake_properties) fake_extra_headers, fake_properties)
self.assertTrue(mock_HTTPSConn.called) mock_update_image_meta.assert_called_with(fake_conn,
self.assertTrue(mock_update_image_meta.called) fake_extra_headers,
fake_properties,
fake_mgt_path)
mock_HTTPSConn.assert_called_with(expect_url_parts[0],
expect_url_parts[1])
mock_validate_image.assert_called_with(fake_conn, mock_validate_image.assert_called_with(fake_conn,
expected_url, expected_url,
fake_extra_headers, fake_extra_headers,