summaryrefslogtreecommitdiff
path: root/openstackclient/tests
diff options
context:
space:
mode:
authorMyeongchul Chae <cocahack@naver.com>2020-08-16 13:44:45 +0000
committerMyeongchul Chae <cocahack@naver.com>2020-09-10 16:12:11 +0000
commitfbd2c00b8999202917671bcdb39298eb39c3ad47 (patch)
tree26bb3ba3bad20e07a0ac78ab8ff29a0c0e07c16c /openstackclient/tests
parent95cc05bdf6f62f14970a722d09010c4195951671 (diff)
downloadpython-openstackclient-fbd2c00b8999202917671bcdb39298eb39c3ad47.tar.gz
Fix --image-property option in 'create server'
There was a problem that the '-image-property' option, which can be used to create an instance, did not work as intended. I found that there were two problems with this option. First, I cannot select an image as its metadata. The second is that when there are multiple images available, the desired image may not be selected depending on the situation. This patch solves these two problems. I wrote the test case with these two problems considered together. Change-Id: Ib2745d7e067056ff4ca8bfaf6cff492d0dacb73a story: #2007860
Diffstat (limited to 'openstackclient/tests')
-rw-r--r--openstackclient/tests/unit/compute/v2/test_server.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/openstackclient/tests/unit/compute/v2/test_server.py b/openstackclient/tests/unit/compute/v2/test_server.py
index 7e4c71c5..6c9497b5 100644
--- a/openstackclient/tests/unit/compute/v2/test_server.py
+++ b/openstackclient/tests/unit/compute/v2/test_server.py
@@ -2048,6 +2048,65 @@ class TestServerCreate(TestServer):
self.cmd.take_action,
parsed_args)
+ def test_server_create_image_property_with_image_list(self):
+ arglist = [
+ '--image-property',
+ 'owner_specified.openstack.object=image/cirros',
+ '--flavor', 'flavor1',
+ '--nic', 'none',
+ self.new_server.name,
+ ]
+
+ verifylist = [
+ ('image_property',
+ {'owner_specified.openstack.object': 'image/cirros'}),
+ ('flavor', 'flavor1'),
+ ('nic', ['none']),
+ ('server_name', self.new_server.name),
+ ]
+ # create a image_info as the side_effect of the fake image_list()
+ image_info = {
+ 'properties': {
+ 'owner_specified.openstack.object': 'image/cirros'
+ }
+ }
+
+ target_image = image_fakes.FakeImage.create_one_image(image_info)
+ another_image = image_fakes.FakeImage.create_one_image({})
+ self.images_mock.return_value = [target_image, another_image]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = dict(
+ files={},
+ reservation_id=None,
+ min_count=1,
+ max_count=1,
+ security_groups=[],
+ userdata=None,
+ key_name=None,
+ availability_zone=None,
+ block_device_mapping_v2=[],
+ nics='none',
+ meta=None,
+ scheduler_hints={},
+ config_drive=None,
+ )
+
+ # ServerManager.create(name, image, flavor, **kwargs)
+ self.servers_mock.create.assert_called_with(
+ self.new_server.name,
+ target_image,
+ self.flavor,
+ **kwargs
+ )
+
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.datalist(), data)
+
def test_server_create_invalid_hint(self):
# Not a key-value pair
arglist = [