Skip to content

Commit

Permalink
Merge "functional: Unify '_build_minimal_create_server_request' imple…
Browse files Browse the repository at this point in the history
…mentations"
  • Loading branch information
Zuul authored and openstack-gerrit committed Dec 12, 2019
2 parents 74a2671 + d888d9b commit ed503ce
Showing 1 changed file with 43 additions and 22 deletions.
65 changes: 43 additions & 22 deletions nova/tests/functional/integrated_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,29 @@ def _wait_for_state_change(self, admin_api, server, expected_status,
return self._wait_for_server_parameter(
admin_api, server, {'status': expected_status}, max_retries)

def _build_minimal_create_server_request(self, api, name, image_uuid=None,
flavor_id=None, networks=None,
az=None, host=None):
def _build_minimal_create_server_request(self, api, name=None,
image_uuid=None, flavor_id=None,
networks=None, az=None,
host=None):
server = {}

# We now have a valid imageId
server['imageRef'] = image_uuid or api.get_images()[0]['id']
if not image_uuid:
# NOTE(takashin): In API version 2.36, image APIs were deprecated.
# In API version 2.36 or greater, self.api.get_images() returns
# a 404 error. In that case, 'image_uuid' should be specified.
image_uuid = api.get_images()[0]['id']
server['imageRef'] = image_uuid

if not name:
name = ''.join(
random.choice(string.ascii_lowercase) for i in range(10))
server['name'] = name

if not flavor_id:
# Set a valid flavorId
flavor_id = api.get_flavors()[1]['id']
server['flavorRef'] = ('http://fake.server/%s' % flavor_id)
server['name'] = name
flavor_id = api.get_flavors()[0]['id']
server['flavorRef'] = 'http://fake.server/%s' % flavor_id

if networks is not None:
server['networks'] = networks
if az is not None:
Expand Down Expand Up @@ -310,24 +320,35 @@ def get_unused_flavor_name_id(self):
def get_invalid_image(self):
return uuids.fake

def _build_minimal_create_server_request(self, image_uuid=None):
def _build_minimal_create_server_request(self, name=None, image_uuid=None,
flavor_id=None, networks=None,
az=None, host=None):
server = {}

# NOTE(takashin): In API version 2.36, image APIs were deprecated.
# In API version 2.36 or greater, self.api.get_images() returns
# a 404 error. In that case, 'image_uuid' should be specified.
server[self._image_ref_parameter] = (image_uuid or
self.api.get_images()[0]['id'])
if not image_uuid:
# NOTE(takashin): In API version 2.36, image APIs were deprecated.
# In API version 2.36 or greater, self.api.get_images() returns
# a 404 error. In that case, 'image_uuid' should be specified.
image_uuid = self.api.get_images()[0]['id']
server['imageRef'] = image_uuid

# Set a valid flavorId
flavor = self.api.get_flavors()[0]
LOG.debug("Using flavor: %s", flavor)
server[self._flavor_ref_parameter] = ('http://fake.server/%s'
% flavor['id'])
if not name:
name = ''.join(
random.choice(string.ascii_lowercase) for i in range(10))
server['name'] = name

# Set a valid server name
server_name = self.get_unused_server_name()
server['name'] = server_name
if not flavor_id:
# Set a valid flavorId
flavor_id = self.api.get_flavors()[0]['id']
server['flavorRef'] = 'http://fake.server/%s' % flavor_id

if networks is not None:
server['networks'] = networks
if az is not None:
server['availability_zone'] = az
# This requires at least microversion 2.74 to work
if host is not None:
server['host'] = host
return server

def _create_flavor_body(self, name, ram, vcpus, disk, ephemeral, id, swap,
Expand Down

0 comments on commit ed503ce

Please sign in to comment.