diff options
author | 2017-11-30 11:57:40 -0700 | |
---|---|---|
committer | 2017-11-30 11:57:40 -0700 | |
commit | 91d2fd9f9249126b135040b7f86387f887a414b3 (patch) | |
tree | 6438149a143cb319da6d366e362319d10ebc36d6 | |
parent | 43151f4e44e64b8436bed234f2dcb60dfc643687 (diff) |
Added exception handling around adding security groups.
When a VM instance has a security group associated with it and
the client attempts to add the same security group, a Pike pod
now raises a ClientException where previous releases simply return
None. This patch adds the appropriate exception handling that
allows several existing tests to pass not only with Pike but also
with all OpenStack versions.
JIRA: SNAPS-239
Change-Id: I282df5a2b516dab415ba5e2e7208176f2ba3f270
Signed-off-by: spisarski <s.pisarski@cablelabs.com>
-rw-r--r-- | snaps/openstack/utils/nova_utils.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/snaps/openstack/utils/nova_utils.py b/snaps/openstack/utils/nova_utils.py index ffc9240..b735ee2 100644 --- a/snaps/openstack/utils/nova_utils.py +++ b/snaps/openstack/utils/nova_utils.py @@ -21,7 +21,7 @@ from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import rsa from novaclient.client import Client -from novaclient.exceptions import NotFound +from novaclient.exceptions import NotFound, ClientException from snaps import file_utils from snaps.domain.flavor import Flavor @@ -605,7 +605,18 @@ def add_security_group(nova, vm, security_group_name): :param vm: the OpenStack server object (VM) to alter :param security_group_name: the name of the security group to add """ - nova.servers.add_security_group(str(vm.id), security_group_name) + try: + nova.servers.add_security_group(str(vm.id), security_group_name) + except ClientException as e: + sec_grp_names = get_server_security_group_names(nova, vm) + if security_group_name in sec_grp_names: + logger.warn('Security group [%s] already added to VM [%s]', + security_group_name, vm.name) + return + + logger.error('Unexpected error while adding security group [%s] - %s', + security_group_name, e) + raise def remove_security_group(nova, vm, security_group): |