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

@ -214,4 +214,4 @@ class PowerVCDriverTestCase(unittest.TestCase):
self.assertEqual(expected_ret_dic,
ret_dic,
"return stats should be matched")
'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

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:

View File

@ -18,11 +18,14 @@ 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__),
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")]))
"powervc_test_1.conf")]
)
)
try:
p1.start()
config.parse_power_config([], "powervc-baseproject", None)
@ -35,15 +38,17 @@ class PVCConfigTest(testtools.TestCase):
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__),
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__),
["%s%s%s" % (os.path.dirname(__file__),
os.sep,
"powervc_test_2.conf")]]))
"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,7 +34,8 @@ 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,
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 '

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

@ -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,7 +175,7 @@ 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. " \
LOG.debug("Service: VM %(vm_id)s successfully rebooted. "
"Current status: %(state)s" % vm_status_dict)
raise loopingcall.LoopingCallDone(True)
@ -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