tests: Convert image tests to use 'parse_output'
Change-Id: I5f256d466d503d70d1f380016f9c8f5a0d9e395f Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
parent
abf1a7cc4b
commit
dc03ce98de
openstackclient/tests/functional/image
@ -10,7 +10,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import json
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import fixtures
|
import fixtures
|
||||||
@ -22,41 +21,37 @@ class ImageTests(base.BaseImageTests):
|
|||||||
"""Functional tests for Image commands"""
|
"""Functional tests for Image commands"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(ImageTests, self).setUp()
|
super().setUp()
|
||||||
|
|
||||||
if not self.haz_v1_api:
|
if not self.haz_v1_api:
|
||||||
self.skipTest('No Image v1 API present')
|
self.skipTest('No Image v1 API present')
|
||||||
|
|
||||||
self.name = uuid.uuid4().hex
|
|
||||||
json_output = json.loads(self.openstack(
|
|
||||||
'--os-image-api-version 1 '
|
|
||||||
'image create -f json ' +
|
|
||||||
self.name
|
|
||||||
))
|
|
||||||
self.image_id = json_output["id"]
|
|
||||||
self.assertOutput(self.name, json_output['name'])
|
|
||||||
|
|
||||||
ver_fixture = fixtures.EnvironmentVariable(
|
ver_fixture = fixtures.EnvironmentVariable(
|
||||||
'OS_IMAGE_API_VERSION', '1'
|
'OS_IMAGE_API_VERSION', '1'
|
||||||
)
|
)
|
||||||
self.useFixture(ver_fixture)
|
self.useFixture(ver_fixture)
|
||||||
|
|
||||||
|
self.name = uuid.uuid4().hex
|
||||||
|
output = self.openstack(
|
||||||
|
'image create ' + self.name,
|
||||||
|
parse_output=True,
|
||||||
|
)
|
||||||
|
self.image_id = output["id"]
|
||||||
|
self.assertOutput(self.name, output['name'])
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
try:
|
try:
|
||||||
self.openstack(
|
self.openstack('image delete ' + self.image_id)
|
||||||
'--os-image-api-version 1 '
|
|
||||||
'image delete ' +
|
|
||||||
self.image_id
|
|
||||||
)
|
|
||||||
finally:
|
finally:
|
||||||
super(ImageTests, self).tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
def test_image_list(self):
|
def test_image_list(self):
|
||||||
json_output = json.loads(self.openstack(
|
output = self.openstack(
|
||||||
'image list -f json '
|
'image list'
|
||||||
))
|
)
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
self.name,
|
self.name,
|
||||||
[img['Name'] for img in json_output]
|
[img['Name'] for img in output]
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_image_attributes(self):
|
def test_image_attributes(self):
|
||||||
@ -71,24 +66,24 @@ class ImageTests(base.BaseImageTests):
|
|||||||
'--public ' +
|
'--public ' +
|
||||||
self.name
|
self.name
|
||||||
)
|
)
|
||||||
json_output = json.loads(self.openstack(
|
output = self.openstack(
|
||||||
'image show -f json ' +
|
'image show ' + self.name,
|
||||||
self.name
|
parse_output=True,
|
||||||
))
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
4,
|
4,
|
||||||
json_output["min_disk"],
|
output["min_disk"],
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
5,
|
5,
|
||||||
json_output["min_ram"],
|
output["min_ram"],
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
'qcow2',
|
'qcow2',
|
||||||
json_output['disk_format'],
|
output['disk_format'],
|
||||||
)
|
)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
json_output["is_public"],
|
output["is_public"],
|
||||||
)
|
)
|
||||||
|
|
||||||
# Test properties
|
# Test properties
|
||||||
@ -99,11 +94,11 @@ class ImageTests(base.BaseImageTests):
|
|||||||
'--public ' +
|
'--public ' +
|
||||||
self.name
|
self.name
|
||||||
)
|
)
|
||||||
json_output = json.loads(self.openstack(
|
output = self.openstack(
|
||||||
'image show -f json ' +
|
'image show ' + self.name,
|
||||||
self.name
|
parse_output=True,
|
||||||
))
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
{'a': 'b', 'c': 'd'},
|
{'a': 'b', 'c': 'd'},
|
||||||
json_output["properties"],
|
output["properties"],
|
||||||
)
|
)
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import json
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import fixtures
|
import fixtures
|
||||||
@ -24,65 +23,62 @@ class ImageTests(base.BaseImageTests):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(ImageTests, self).setUp()
|
super(ImageTests, self).setUp()
|
||||||
|
|
||||||
self.name = uuid.uuid4().hex
|
|
||||||
self.image_tag = 'my_tag'
|
|
||||||
self.image_tag1 = 'random'
|
|
||||||
json_output = json.loads(self.openstack(
|
|
||||||
'--os-image-api-version 2 '
|
|
||||||
'image create -f json --tag {tag} {name}'.format(
|
|
||||||
tag=self.image_tag, name=self.name)
|
|
||||||
))
|
|
||||||
self.image_id = json_output["id"]
|
|
||||||
self.assertOutput(self.name, json_output['name'])
|
|
||||||
|
|
||||||
ver_fixture = fixtures.EnvironmentVariable(
|
ver_fixture = fixtures.EnvironmentVariable(
|
||||||
'OS_IMAGE_API_VERSION', '2'
|
'OS_IMAGE_API_VERSION', '2'
|
||||||
)
|
)
|
||||||
self.useFixture(ver_fixture)
|
self.useFixture(ver_fixture)
|
||||||
|
|
||||||
|
self.name = uuid.uuid4().hex
|
||||||
|
self.image_tag = 'my_tag'
|
||||||
|
self.image_tag1 = 'random'
|
||||||
|
output = self.openstack(
|
||||||
|
'image create --tag {tag} {name}'.format(
|
||||||
|
tag=self.image_tag, name=self.name),
|
||||||
|
parse_output=True,
|
||||||
|
)
|
||||||
|
self.image_id = output["id"]
|
||||||
|
self.assertOutput(self.name, output['name'])
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
try:
|
try:
|
||||||
self.openstack(
|
self.openstack('image delete ' + self.image_id)
|
||||||
'--os-image-api-version 2 '
|
|
||||||
'image delete ' +
|
|
||||||
self.image_id
|
|
||||||
)
|
|
||||||
finally:
|
finally:
|
||||||
super(ImageTests, self).tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
def test_image_list(self):
|
def test_image_list(self):
|
||||||
json_output = json.loads(self.openstack(
|
output = self.openstack('image list', parse_output=True)
|
||||||
'image list -f json '
|
|
||||||
))
|
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
self.name,
|
self.name,
|
||||||
[img['Name'] for img in json_output]
|
[img['Name'] for img in output]
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_image_list_with_name_filter(self):
|
def test_image_list_with_name_filter(self):
|
||||||
json_output = json.loads(self.openstack(
|
output = self.openstack(
|
||||||
'image list --name ' + self.name + ' -f json'
|
'image list --name ' + self.name,
|
||||||
))
|
parse_output=True,
|
||||||
|
)
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
self.name,
|
self.name,
|
||||||
[img['Name'] for img in json_output]
|
[img['Name'] for img in output]
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_image_list_with_status_filter(self):
|
def test_image_list_with_status_filter(self):
|
||||||
json_output = json.loads(self.openstack(
|
output = self.openstack(
|
||||||
'image list ' + ' --status active -f json'
|
'image list --status active',
|
||||||
))
|
parse_output=True,
|
||||||
|
)
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
'active',
|
'active',
|
||||||
[img['Status'] for img in json_output]
|
[img['Status'] for img in output]
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_image_list_with_tag_filter(self):
|
def test_image_list_with_tag_filter(self):
|
||||||
json_output = json.loads(self.openstack(
|
output = self.openstack(
|
||||||
'image list --tag ' + self.image_tag + ' --tag ' +
|
'image list --tag ' + self.image_tag + ' --tag ' +
|
||||||
self.image_tag1 + ' --long -f json'
|
self.image_tag1 + ' --long',
|
||||||
))
|
parse_output=True,
|
||||||
for taglist in [img['Tags'] for img in json_output]:
|
)
|
||||||
|
for taglist in [img['Tags'] for img in output]:
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
self.image_tag,
|
self.image_tag,
|
||||||
taglist
|
taglist
|
||||||
@ -103,21 +99,21 @@ class ImageTests(base.BaseImageTests):
|
|||||||
'--public ' +
|
'--public ' +
|
||||||
self.name
|
self.name
|
||||||
)
|
)
|
||||||
json_output = json.loads(self.openstack(
|
output = self.openstack(
|
||||||
'image show -f json ' +
|
'image show ' + self.name,
|
||||||
self.name
|
parse_output=True,
|
||||||
))
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
4,
|
4,
|
||||||
json_output["min_disk"],
|
output["min_disk"],
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
5,
|
5,
|
||||||
json_output["min_ram"],
|
output["min_ram"],
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
'public',
|
'public',
|
||||||
json_output["visibility"],
|
output["visibility"],
|
||||||
)
|
)
|
||||||
|
|
||||||
# Test properties
|
# Test properties
|
||||||
@ -129,12 +125,12 @@ class ImageTests(base.BaseImageTests):
|
|||||||
'--public ' +
|
'--public ' +
|
||||||
self.name
|
self.name
|
||||||
)
|
)
|
||||||
json_output = json.loads(self.openstack(
|
output = self.openstack(
|
||||||
'image show -f json ' +
|
'image show ' + self.name,
|
||||||
self.name
|
parse_output=True,
|
||||||
))
|
)
|
||||||
self.assertIn("a", json_output["properties"])
|
self.assertIn("a", output["properties"])
|
||||||
self.assertIn("c", json_output["properties"])
|
self.assertIn("c", output["properties"])
|
||||||
|
|
||||||
self.openstack(
|
self.openstack(
|
||||||
'image unset ' +
|
'image unset ' +
|
||||||
@ -143,30 +139,30 @@ class ImageTests(base.BaseImageTests):
|
|||||||
'--property hw_rng_model ' +
|
'--property hw_rng_model ' +
|
||||||
self.name
|
self.name
|
||||||
)
|
)
|
||||||
json_output = json.loads(self.openstack(
|
output = self.openstack(
|
||||||
'image show -f json ' +
|
'image show ' + self.name,
|
||||||
self.name
|
parse_output=True,
|
||||||
))
|
)
|
||||||
self.assertNotIn("a", json_output["properties"])
|
self.assertNotIn("a", output["properties"])
|
||||||
self.assertNotIn("c", json_output["properties"])
|
self.assertNotIn("c", output["properties"])
|
||||||
|
|
||||||
# Test tags
|
# Test tags
|
||||||
self.assertNotIn(
|
self.assertNotIn(
|
||||||
'01',
|
'01',
|
||||||
json_output["tags"]
|
output["tags"]
|
||||||
)
|
)
|
||||||
self.openstack(
|
self.openstack(
|
||||||
'image set ' +
|
'image set ' +
|
||||||
'--tag 01 ' +
|
'--tag 01 ' +
|
||||||
self.name
|
self.name
|
||||||
)
|
)
|
||||||
json_output = json.loads(self.openstack(
|
output = self.openstack(
|
||||||
'image show -f json ' +
|
'image show ' + self.name,
|
||||||
self.name
|
parse_output=True,
|
||||||
))
|
)
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
'01',
|
'01',
|
||||||
json_output["tags"]
|
output["tags"]
|
||||||
)
|
)
|
||||||
|
|
||||||
self.openstack(
|
self.openstack(
|
||||||
@ -174,38 +170,38 @@ class ImageTests(base.BaseImageTests):
|
|||||||
'--tag 01 ' +
|
'--tag 01 ' +
|
||||||
self.name
|
self.name
|
||||||
)
|
)
|
||||||
json_output = json.loads(self.openstack(
|
output = self.openstack(
|
||||||
'image show -f json ' +
|
'image show ' + self.name,
|
||||||
self.name
|
parse_output=True,
|
||||||
))
|
)
|
||||||
self.assertNotIn(
|
self.assertNotIn(
|
||||||
'01',
|
'01',
|
||||||
json_output["tags"]
|
output["tags"]
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_image_set_rename(self):
|
def test_image_set_rename(self):
|
||||||
name = uuid.uuid4().hex
|
name = uuid.uuid4().hex
|
||||||
json_output = json.loads(self.openstack(
|
output = self.openstack(
|
||||||
'image create -f json ' +
|
'image create ' + name,
|
||||||
name
|
parse_output=True,
|
||||||
))
|
)
|
||||||
image_id = json_output["id"]
|
image_id = output["id"]
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
name,
|
name,
|
||||||
json_output["name"],
|
output["name"],
|
||||||
)
|
)
|
||||||
self.openstack(
|
self.openstack(
|
||||||
'image set ' +
|
'image set ' +
|
||||||
'--name ' + name + 'xx ' +
|
'--name ' + name + 'xx ' +
|
||||||
image_id
|
image_id
|
||||||
)
|
)
|
||||||
json_output = json.loads(self.openstack(
|
output = self.openstack(
|
||||||
'image show -f json ' +
|
'image show ' + name + 'xx',
|
||||||
name + 'xx'
|
parse_output=True,
|
||||||
))
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
name + 'xx',
|
name + 'xx',
|
||||||
json_output["name"],
|
output["name"],
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO(dtroyer): This test is incomplete and doesn't properly test
|
# TODO(dtroyer): This test is incomplete and doesn't properly test
|
||||||
@ -213,19 +209,21 @@ class ImageTests(base.BaseImageTests):
|
|||||||
# properly added.
|
# properly added.
|
||||||
def test_image_members(self):
|
def test_image_members(self):
|
||||||
"""Test member add, remove, accept"""
|
"""Test member add, remove, accept"""
|
||||||
json_output = json.loads(self.openstack(
|
output = self.openstack(
|
||||||
'token issue -f json'
|
'token issue',
|
||||||
))
|
parse_output=True,
|
||||||
my_project_id = json_output['project_id']
|
)
|
||||||
|
my_project_id = output['project_id']
|
||||||
|
|
||||||
json_output = json.loads(self.openstack(
|
output = self.openstack(
|
||||||
'image show -f json ' +
|
'image show -f json ' +
|
||||||
self.name
|
self.name,
|
||||||
))
|
parse_output=True,
|
||||||
|
)
|
||||||
# NOTE(dtroyer): Until OSC supports --shared flags in create and set
|
# NOTE(dtroyer): Until OSC supports --shared flags in create and set
|
||||||
# we can not properly test membership. Sometimes the
|
# we can not properly test membership. Sometimes the
|
||||||
# images are shared and sometimes they are not.
|
# images are shared and sometimes they are not.
|
||||||
if json_output["visibility"] == 'shared':
|
if output["visibility"] == 'shared':
|
||||||
self.openstack(
|
self.openstack(
|
||||||
'image add project ' +
|
'image add project ' +
|
||||||
self.name + ' ' +
|
self.name + ' ' +
|
||||||
@ -243,13 +241,14 @@ class ImageTests(base.BaseImageTests):
|
|||||||
'--accept ' +
|
'--accept ' +
|
||||||
self.name
|
self.name
|
||||||
)
|
)
|
||||||
json_output = json.loads(self.openstack(
|
output = self.openstack(
|
||||||
'image list -f json ' +
|
'image list -f json ' +
|
||||||
'--shared'
|
'--shared',
|
||||||
))
|
parse_output=True,
|
||||||
|
)
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
self.name,
|
self.name,
|
||||||
[img['Name'] for img in json_output]
|
[img['Name'] for img in output]
|
||||||
)
|
)
|
||||||
|
|
||||||
self.openstack(
|
self.openstack(
|
||||||
@ -257,13 +256,14 @@ class ImageTests(base.BaseImageTests):
|
|||||||
'--reject ' +
|
'--reject ' +
|
||||||
self.name
|
self.name
|
||||||
)
|
)
|
||||||
json_output = json.loads(self.openstack(
|
output = self.openstack(
|
||||||
'image list -f json ' +
|
'image list -f json ' +
|
||||||
'--shared'
|
'--shared',
|
||||||
))
|
parse_output=True,
|
||||||
|
)
|
||||||
# self.assertNotIn(
|
# self.assertNotIn(
|
||||||
# self.name,
|
# self.name,
|
||||||
# [img['Name'] for img in json_output]
|
# [img['Name'] for img in output]
|
||||||
# )
|
# )
|
||||||
|
|
||||||
self.openstack(
|
self.openstack(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user