Fix flake8 warning and error report

All the flake8 issues have been resolved with this commit.

Change-Id: I637f82c484b3dbecc4827731a13f79c2ba2b9240
Closes-Bug: #1346759
This commit is contained in:
yinym 2014-07-22 14:30:05 +08:00
parent 229f843fbb
commit 8f6cb9fd23
16 changed files with 548 additions and 539 deletions

View File

@ -72,11 +72,11 @@ class PowerVCDriverTestCase(unittest.TestCase):
volume = Volume(vol)
# fake volume after call creating volume from pvc
ret_vol_after_created = {'id': 4321,
'status': 'creating'}
'status': 'creating'}
ret_volume_after_created = Volume(ret_vol_after_created)
# fake volume after call get volume from pvc
ret_vol_get = {'id': 4321,
'status': 'available'}
'status': 'available'}
ret_volume_get = Volume(ret_vol_get)
# mock create volume restAPI
@ -90,8 +90,8 @@ class PowerVCDriverTestCase(unittest.TestCase):
dic = self.powervc_cinder_driver.create_volume(volume)
self.assertEqual({'status': 'available',
'metadata': {'pvc:id': 4321}},
dic, "return vol doesn't match")
'metadata': {'pvc:id': 4321}},
dic, "return vol doesn't match")
def test_create_volume_failed(self):
# local volume passed to driver
@ -100,11 +100,11 @@ class PowerVCDriverTestCase(unittest.TestCase):
volume = Volume(vol)
# fake volume after call creating volume from pvc
ret_vol_after_created = {'id': 4321,
'status': 'creating'}
'status': 'creating'}
ret_volume_after_created = Volume(ret_vol_after_created)
# fake volume after call get volume from pvc
ret_vol_get = {'id': 4321,
'status': 'error'}
'status': 'error'}
ret_volume_get = Volume(ret_vol_get)
# mock create volume restAPI
@ -119,7 +119,7 @@ class PowerVCDriverTestCase(unittest.TestCase):
dic = self.powervc_cinder_driver.create_volume(volume)
self.assertEqual({'status': 'error',
'metadata': {'pvc:id': 4321}},
dic, "return vol doesn't match")
dic, "return vol doesn't match")
def test_create_volume_not_found(self):
# local volume passed to driver
@ -128,11 +128,11 @@ class PowerVCDriverTestCase(unittest.TestCase):
volume = Volume(vol)
# fake volume after call creating volume from pvc
ret_vol_after_created = {'id': 4321,
'status': 'creating'}
'status': 'creating'}
ret_volume_after_created = Volume(ret_vol_after_created)
# fake volume after call get volume from pvc
ret_vol_get = {'id': 4321,
'status': 'error'}
'status': 'error'}
ret_volume_get = Volume(ret_vol_get)
# mock create volume restAPI
@ -149,8 +149,8 @@ class PowerVCDriverTestCase(unittest.TestCase):
dic = self.powervc_cinder_driver.create_volume(volume)
self.assertEqual({'status': 'error',
'metadata': {'pvc:id': 4321}},
dic, "return vol doesn't match")
'metadata': {'pvc:id': 4321}},
dic, "return vol doesn't match")
def test_delete_volume_success(self):
#fake volume which will be passed to driver service
@ -169,7 +169,7 @@ class PowerVCDriverTestCase(unittest.TestCase):
#mock rest API
PowerVCService._client.volumes.get = \
mock.MagicMock(side_effect=[existed_volume_get,
after_delete_volume_get])
after_delete_volume_get])
self.powervc_cinder_driver.delete_volume(volume)
@ -213,5 +213,5 @@ class PowerVCDriverTestCase(unittest.TestCase):
ret_dic = self.powervc_cinder_driver.get_volume_stats(True)
self.assertEqual(expected_ret_dic,
ret_dic,
"return stats should be matched")
ret_dic,
'return stats should be matched')

View File

@ -2,7 +2,6 @@
import six
import urllib
import base64
from novaclient import base as client_base
from novaclient.v1_1 import servers
from novaclient.v1_1 import hypervisors
@ -10,7 +9,6 @@ from novaclient.v1_1 import images
from novaclient.v1_1 import flavors
from novaclient.v1_1 import volumes
from novaclient.v1_1.volume_types import VolumeType
from novaclient.openstack.common import strutils
from powervc.common.client.extensions import base
from powervc.common import utils
import logging
@ -92,7 +90,6 @@ class PVCServerManager(servers.ServerManager):
detail = "/detail"
return self._list("/servers%s%s" % (detail, query_string), "servers")
# This function was copied from (/usr/lib/python2.6/site-packages/
# novaclient/v1_1/servers.py) before, but changes needed when activation
# data contains userdata and files, because in a boot action, local OS
@ -372,7 +369,7 @@ class StorageConnectivityGroupManager(client_base.Manager):
"""
try:
return self._list("/storage-connectivity-groups/%s/volumes"
% scgUUID, "volumes", volumes.Volume)
% scgUUID, "volumes", volumes.Volume)
except Exception as e:
LOG.error('A problem was encountered while getting a list of '
'accessible volumes for scg %s: %s '
@ -387,7 +384,7 @@ class StorageConnectivityGroupManager(client_base.Manager):
"""
try:
return self._list("/storage-connectivity-groups/%s/volume-types"
% scgUUID, "volume-types", VolumeType)
% scgUUID, "volume-types", VolumeType)
except Exception as e:
LOG.error('A problem was encountered while getting a list of '
'accessible volume types for scg %s: %s '

View File

@ -7,6 +7,7 @@ from powervc.common.client.config import CONF as CONF
from powervc.common.client.config import OS_OPTS as OS_OPTS
from powervc.common.client.config import PVC_OPTS as PVC_OPTS
from powervc.common.constants import SERVICE_TYPES as SERVICE_TYPES
from powervc.common.gettextutils import _
"""sample useage
@ -47,14 +48,14 @@ def initialize_local_servicecatalog():
return
def new_local_servicecatalog():
LOG.info(_("start to new local keystone client"))
LOG.info(_('start to new local keystone client'))
keystone_version = CONF['openstack']['keystone_version']
keystone = service.KeystoneService(str(SERVICE_TYPES.identity),
keystone_version,
OS_OPTS['auth_url'], OS_OPTS,
None).new_client()
servicecatalog = service.ClientServiceCatalog(OS_OPTS, keystone)
LOG.info(_("finish to new local keystone client"))
LOG.info(_('finish to new local keystone client'))
return servicecatalog
count = 0
@ -65,11 +66,11 @@ def initialize_local_servicecatalog():
LOCAL = new_local_servicecatalog()
return
except Exception, e:
LOG.info(_("Keystone service is not ready. " + str(e)))
LOG.info(_('Keystone service is not ready. ' + str(e)))
count += 1
if count == CONF['openstack']['keystone_max_try_times']:
LOG.error(_("Keystone service is not ready eventually after"
" retries!"))
LOG.error(_('Keystone service is not ready eventually after'
' retries!'))
raise e
time.sleep(CONF['openstack']['keystone_retry_interval'])

View File

@ -361,11 +361,13 @@ class Utils(object):
if not scg:
# If no scg, then it's a IVM based PowerVC,
# return all servers
return self._novaclient.manager.list_all_servers(detailed, search_opts)
return self._novaclient.manager.list_all_servers(
detailed, search_opts)
# accessible_storage_servers to return
accessible_storage_servers = []
all_servers = self._novaclient.manager.list_all_servers(detailed, search_opts)
all_servers = self._novaclient.manager.list_all_servers(
detailed, search_opts)
# Filter the servers for the SCG
for server in all_servers:
@ -566,7 +568,7 @@ class Utils(object):
# If no scg, then it's a IVM based PowerVC,
# return all volumes
return (self._cinderclient.volume_types.
list_all_storage_templates())
list_all_storage_templates())
# accessible_storage_templates to return
accessible_storage_templates = []

View File

@ -18,32 +18,37 @@ class PVCConfigTest(testtools.TestCase):
del config.parse_power_config.power_config_loaded
def test_parse_config_1(self):
p1 = mock.patch('oslo.config.cfg.find_config_files',
new=mock.MagicMock(return_value=["%s%s%s" %
(os.path.dirname(__file__),
os.sep,
"powervc_test_1.conf")]))
p1 = mock.patch(
'oslo.config.cfg.find_config_files',
new=mock.MagicMock(
return_value=["%s%s%s" % (os.path.dirname(__file__),
os.sep,
"powervc_test_1.conf")]
)
)
try:
p1.start()
config.parse_power_config([], "powervc-baseproject", None)
# default value
self.assertEqual(config.CONF.powervc.auth_url,
"http://localhost:5000/v2.0/")
"http://localhost:5000/v2.0/")
# value in file
self.assertEqual(config.CONF.powervc.qpid_port, 5679)
finally:
p1.stop()
def test_parse_config_2(self):
p2 = mock.patch('oslo.config.cfg.find_config_files',
new=mock.MagicMock(side_effect=[["%s%s%s" %
(os.path.dirname(__file__),
os.sep,
"powervc_test_1.conf")],
["%s%s%s" %
(os.path.dirname(__file__),
os.sep,
"powervc_test_2.conf")]]))
p2 = mock.patch(
'oslo.config.cfg.find_config_files',
new=mock.MagicMock(
side_effect=[["%s%s%s" % (os.path.dirname(__file__),
os.sep,
"powervc_test_1.conf")],
["%s%s%s" % (os.path.dirname(__file__),
os.sep,
"powervc_test_2.conf")]]
)
)
try:
p2.start()
config.parse_power_config([], "baseproject", None)

View File

@ -6,6 +6,7 @@ PowerVC Driver ImageManager Configuration
from oslo.config import cfg
import powervc.common.config as common_config
from powervc.common.gettextutils import _
from powervc.glance.common import constants
CONF = common_config.CONF
@ -33,11 +34,12 @@ CONF.register_opts(image_opts, group='powervc')
Refer to the file glance/api/middleware/context.py , register the config
option named 'owner_is_tenant' to default group.
"""
CONF.register_opt(cfg.BoolOpt('owner_is_tenant', default=True,
help=_('When true, this option sets the owner of '
'an image to be the tenant. Otherwise, the'
' owner of the image will be the '
'authenticated user issuing the request.')))
CONF.register_opt(
cfg.BoolOpt('owner_is_tenant', default=True,
help=_('When true, this option sets the owner of '
'an image to be the tenant. Otherwise, the'
' owner of the image will be the '
'authenticated user issuing the request.')))
def parse_config(*args, **kwargs):

View File

@ -39,7 +39,9 @@ IMAGE_UPDATE_PARAMS_FILTER = ['owner', 'location']
IMAGE_UNESCAPE_PROPERTIES = ['configuration_strategy']
# List of v2image update parameters to filter out
v2IMAGE_UPDATE_PARAMS_FILTER = IMAGE_UPDATE_PARAMS_FILTER + ['deleted', 'size', 'checksum']
v2IMAGE_UPDATE_PARAMS_FILTER = IMAGE_UPDATE_PARAMS_FILTER + ['deleted',
'size',
'checksum']
# List of image properties to filter out during an update
IMAGE_UPDATE_PROPERTIES_FILTER = [consts.POWERVC_UUID_KEY,

View File

@ -1403,7 +1403,8 @@ class PowerVCImageManager(service.Service):
field_dict, update_field_dict = self._get_v1image_create_fields(
src_image, image_owner, image_endpoint)
# Community fix needs the property 'checksum' must be set
field_dict['checksum'] = self._get_image_checksum(src_image.to_dict())
field_dict['checksum'] = self._get_image_checksum(
src_image.to_dict())
new_image = v1images.create(**field_dict)
updated_image = None
if len(update_field_dict) > 0:

View File

@ -62,7 +62,7 @@ class TestPowerVCNeutronAgent(unittest.TestCase):
local_port = mock.MagicMock()
local_port.get = mock.MagicMock(
return_value="network:router_interface")
return_value="network:router_interface")
self.powervc_neutron_agent.pvc = mock.MagicMock()
self.powervc_neutron_agent.pvc.create_port = mock.MagicMock()
@ -93,8 +93,7 @@ class TestPowerVCNeutronAgent(unittest.TestCase):
local_port = mock.MagicMock()
local_port.get = mock.MagicMock(
side_effect=[constants.STATUS_CREATING,
constants.STATUS_ACTIVE])
side_effect=[constants.STATUS_CREATING, constants.STATUS_ACTIVE])
self.powervc_neutron_agent.db = mock.MagicMock()
self.powervc_neutron_agent.db.get_port = mock.MagicMock(
return_value=local_port)
@ -112,8 +111,7 @@ class TestPowerVCNeutronAgent(unittest.TestCase):
local_port = mock.MagicMock()
local_port.get = mock.MagicMock(
side_effect=[constants.STATUS_CREATING,
constants.STATUS_CREATING])
side_effect=[constants.STATUS_CREATING, constants.STATUS_CREATING])
self.powervc_neutron_agent.db = mock.MagicMock()
self.powervc_neutron_agent.db.get_port = mock.MagicMock(
return_value=local_port)

View File

@ -175,8 +175,8 @@ class PowerVCService(object):
else:
vm_status_dict = {'vm_id': server.id,
'state': pvc_vm_states.ACTIVE}
LOG.debug("Service: VM %(vm_id)s successfully rebooted. " \
"Current status: %(state)s" % vm_status_dict)
LOG.debug("Service: VM %(vm_id)s successfully rebooted. "
"Current status: %(state)s" % vm_status_dict)
raise loopingcall.LoopingCallDone(True)
def _wait_for_resize_state_change(self, context, migration,
@ -469,7 +469,7 @@ class PowerVCService(object):
if (task_state == task_states.ACTIVATING):
LOG.debug("The task status of the instance: %s"
% task_state)
reason = _("The instance in the task status: %s can not" \
reason = _("The instance in the task status: %s can not"
" be stopped."
% task_state)
raise exception.InstanceUnacceptable(instance_id=server.id,

View File

@ -4,6 +4,7 @@ import re
from eventlet import greenthread
import powervc.common.config as cfg
from powervc.common.gettextutils import _
from nova.compute import flavors
from nova import exception
from nova import db

View File

@ -403,10 +403,10 @@ class PowerVCDriverTestCase(test.NoDBTestCase):
pvc_driver.snapshot(context, instance, image_id,
update_task_state)
update_task_state.assert_any_call(
task_state=task_states.IMAGE_PENDING_UPLOAD)
task_state=task_states.IMAGE_PENDING_UPLOAD)
update_task_state.assert_any_call(
task_state=task_states.IMAGE_UPLOADING,
expected_state=task_states.IMAGE_PENDING_UPLOAD)
task_state=task_states.IMAGE_UPLOADING,
expected_state=task_states.IMAGE_PENDING_UPLOAD)
def tearDown(self):
super(PowerVCDriverTestCase, self).tearDown()
@ -459,10 +459,10 @@ class TestDriver(unittest.TestCase):
_update_local_instance_by_pvc_created_instance = \
mock.MagicMock()
resultServer = self.powervc_driver.spawn(context,
instance,
image_meta,
injected_files,
admin_password)
instance,
image_meta,
injected_files,
admin_password)
self.assertEquals(createFinished,
resultServer,
'success')
@ -521,8 +521,8 @@ class TestDriver(unittest.TestCase):
'OS-EXT-STS:task_state', None)
self.powervc_driver._service._manager.get = \
mock.MagicMock(
side_effect=[manager_get_server_from_instance,
manager_get_server_from_destroy_instance])
side_effect=[manager_get_server_from_instance,
manager_get_server_from_destroy_instance])
self.powervc_driver._service._manager.delete = \
mock.MagicMock()
self.powervc_driver._service._validate_response = \
@ -562,7 +562,7 @@ class TestDriver(unittest.TestCase):
self.powervc_driver._service._manager.get = \
mock.MagicMock(
side_effect=[manager_get_server_from_instance,
manager_get_server_from_destroy_instance])
manager_get_server_from_destroy_instance])
self.powervc_driver._service._manager.delete = mock.MagicMock()
self.powervc_driver._service._validate_response = mock.MagicMock()
self.assertRaises(exception.InstanceTerminationFailure,