summaryrefslogtreecommitdiffstats
path: root/nfvbench/compute.py
diff options
context:
space:
mode:
authorKerim Gokarslan <kgokarsl@cisco.com>2017-10-13 17:29:58 -0700
committerKerim Gokarslan <kgokarsl@cisco.com>2017-10-16 11:53:49 -0700
commita79debff4a6436522feebd2221865a2a6a917a58 (patch)
treee798895746a4edddc083b6e618f766d7905a7fbc /nfvbench/compute.py
parent211bc02b88a19153eb33f9a4f6670638bf469676 (diff)
NFVBENCH-40 Add pylint to tox
Change-Id: Ic55a07145f27c4cfaa6df5523df3940ca4433af1 Signed-off-by: Kerim Gokarslan <kgokarsl@cisco.com>
Diffstat (limited to 'nfvbench/compute.py')
-rw-r--r--nfvbench/compute.py36
1 files changed, 15 insertions, 21 deletions
diff --git a/nfvbench/compute.py b/nfvbench/compute.py
index 5806164..575744c 100644
--- a/nfvbench/compute.py
+++ b/nfvbench/compute.py
@@ -11,16 +11,16 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
+"""Module for Openstack compute operations"""
+import os
+import time
+import traceback
-'''Module for Openstack compute operations'''
-from glanceclient import exc as glance_exception
import keystoneauth1
from log import LOG
import novaclient
-import os
-import time
-import traceback
+from glanceclient import exc as glance_exception
try:
from glanceclient.openstack.common.apiclient.exceptions import NotFound as GlanceImageNotFound
@@ -29,7 +29,6 @@ except ImportError:
class Compute(object):
-
def __init__(self, nova_client, glance_client, neutron_client, config):
self.novaclient = nova_client
self.glance_client = glance_client
@@ -137,10 +136,9 @@ class Compute(object):
'''
if ssh_access.public_key_file:
return self.add_public_key(kp_name, ssh_access.public_key_file)
- else:
- keypair = self.create_keypair(kp_name, None)
- ssh_access.private_key = keypair.private_key
- return keypair
+ keypair = self.create_keypair(kp_name, None)
+ ssh_access.private_key = keypair.private_key
+ return keypair
def find_network(self, label):
net = self.novaclient.networks.find(label=label)
@@ -290,7 +288,7 @@ class Compute(object):
if hyp.zone == zone:
# matches
return az_host
- # else continue - another zone with same host name?
+ # else continue - another zone with same host name?
# no match
LOG.error('No match for availability zone and host ' + az_host)
return None
@@ -375,16 +373,15 @@ class Compute(object):
LOG.warning('Operation Forbidden: could not retrieve list of hypervisors'
' (likely no permission)')
- hypervisor_list = filter(lambda h: h.status == 'enabled' and h.state == 'up',
- hypervisor_list)
+ hypervisor_list = [h for h in hypervisor_list if h.status == 'enabled' and h.state == 'up']
if self.config.availability_zone:
- host_list = filter(lambda h: h.zone == self.config.availability_zone, host_list)
+ host_list = [h for h in host_list if h.zone == self.config.availability_zone]
if self.config.compute_nodes:
- host_list = filter(lambda h: h.host in self.config.compute_nodes, host_list)
+ host_list = [h for h in host_list if h.host in self.config.compute_nodes]
hosts = [h.hypervisor_hostname for h in hypervisor_list]
- host_list = filter(lambda h: h.host in hosts, host_list)
+ host_list = [h for h in host_list if h.host in hosts]
avail_list = []
for host in host_list:
@@ -408,10 +405,7 @@ class Compute(object):
try:
server_instance_1 = self.novaclient.servers.get(vm_instance1)
server_instance_2 = self.novaclient.servers.get(vm_instance2)
- if server_instance_1.hostId == server_instance_2.hostId:
- return True
- else:
- return False
+ return bool(server_instance_1.hostId == server_instance_2.hostId)
except novaclient.exceptions:
LOG.warning("Exception in retrieving the hostId of servers")
@@ -420,7 +414,7 @@ class Compute(object):
# check first the security group exists
sec_groups = self.neutronclient.list_security_groups()['security_groups']
group = [x for x in sec_groups if x['name'] == self.config.security_group_name]
- if len(group) > 0:
+ if group:
return group[0]
body = {