Merge "Fix empty values validation in nova server"

This commit is contained in:
Jenkins 2016-08-02 13:05:21 +00:00 committed by Gerrit Code Review
commit deb4031023
2 changed files with 30 additions and 4 deletions

View File

@ -1344,7 +1344,8 @@ class Server(stack_user.StackUser, sh.SchedulerHintsMixin,
'swap_size must be specified.') 'swap_size must be specified.')
raise exception.StackValidationFailed(message=msg) raise exception.StackValidationFailed(message=msg)
if any((volume_id, snapshot_id, image_id)): if any((volume_id is not None, snapshot_id is not None,
image_id is not None)):
bootable_vol = True bootable_vol = True
return bootable_vol return bootable_vol
@ -1399,7 +1400,7 @@ class Server(stack_user.StackUser, sh.SchedulerHintsMixin,
# make sure the image exists if specified. # make sure the image exists if specified.
image = self.properties[self.IMAGE] image = self.properties[self.IMAGE]
if not image and not bootable_vol: if image is None and not bootable_vol:
msg = _('Neither image nor bootable volume is specified for' msg = _('Neither image nor bootable volume is specified for'
' instance %s') % self.name ' instance %s') % self.name
raise exception.StackValidationFailed(message=msg) raise exception.StackValidationFailed(message=msg)
@ -1415,7 +1416,7 @@ class Server(stack_user.StackUser, sh.SchedulerHintsMixin,
networks_with_port = False networks_with_port = False
for network in networks: for network in networks:
networks_with_port = (networks_with_port or networks_with_port = (networks_with_port or
network.get(self.NETWORK_PORT)) network.get(self.NETWORK_PORT) is not None)
self._validate_network(network) self._validate_network(network)
# retrieve provider's absolute limits if it will be needed # retrieve provider's absolute limits if it will be needed

View File

@ -1064,6 +1064,10 @@ class ServersTest(common.HeatTestCase):
'instance server_with_bootable_volume', 'instance server_with_bootable_volume',
six.text_type(ex)) six.text_type(ex))
web_server['Properties']['image'] = ''
server = create_server('vdb')
self.assertIsNone(server.validate())
def test_server_validate_with_nova_keypair_resource(self): def test_server_validate_with_nova_keypair_resource(self):
stack_name = 'srv_val_test' stack_name = 'srv_val_test'
nova_keypair_template = ''' nova_keypair_template = '''
@ -1359,7 +1363,7 @@ class ServersTest(common.HeatTestCase):
(tmpl, stack) = self._setup_test_stack(stack_name) (tmpl, stack) = self._setup_test_stack(stack_name)
tmpl['Resources']['WebServer']['Properties']['networks'] = [ tmpl['Resources']['WebServer']['Properties']['networks'] = [
{'port': 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'}] {'port': ''}]
tmpl['Resources']['WebServer']['Properties'][ tmpl['Resources']['WebServer']['Properties'][
'security_groups'] = ['my_security_group'] 'security_groups'] = ['my_security_group']
self.patchobject(nova.NovaClientPlugin, '_create', self.patchobject(nova.NovaClientPlugin, '_create',
@ -2689,6 +2693,27 @@ class ServersTest(common.HeatTestCase):
self.stub_VolumeConstraint_validate() self.stub_VolumeConstraint_validate()
self.assertIsNone(server.validate()) self.assertIsNone(server.validate())
@mock.patch.object(nova.NovaClientPlugin, '_create')
def test_validate_bdm_v2_with_unresolved_volume(self, mock_create):
stack_name = 'v2_properties'
(tmpl, stack) = self._setup_test_stack(stack_name)
del tmpl['Resources']['WebServer']['Properties']['image']
# empty string indicates that volume is unresolved
bdm_v2 = [{'volume_id': ''}]
wsp = tmpl.t['Resources']['WebServer']['Properties']
wsp['block_device_mapping_v2'] = bdm_v2
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_create_image_err',
resource_defns['WebServer'], stack)
self.patchobject(nova.NovaClientPlugin, 'get_flavor',
return_value=self.mock_flavor)
self.patchobject(glance.GlanceClientPlugin, 'get_image',
return_value=self.mock_image)
self.stub_VolumeConstraint_validate()
self.assertIsNone(server.validate())
@mock.patch.object(nova.NovaClientPlugin, '_create') @mock.patch.object(nova.NovaClientPlugin, '_create')
def test_validate_bdm_v2_properties_no_bootable_vol(self, mock_create): def test_validate_bdm_v2_properties_no_bootable_vol(self, mock_create):
stack_name = 'v2_properties' stack_name = 'v2_properties'