Enable pep8 checks

Enables excluded pep8 checks and fixes existing the related errors

Change-Id: Ib3a909d79b9726567c1cebf5881d1878d91ee052
This commit is contained in:
Nicholas Jones 2017-07-27 12:26:44 -05:00
parent 50de35d7e8
commit 747480367b
117 changed files with 8040 additions and 7955 deletions

View File

@ -26,6 +26,7 @@ def setup_app(config):
logger.info('Starting Audit...')
return app
def main():
dir_name = os.path.dirname(__file__)
drive, path_and_file = os.path.splitdrive(dir_name)

View File

@ -23,6 +23,7 @@ def setup_app(config):
logger.info('Starting FMS...')
return app
def main():
dir_name = os.path.dirname(__file__)
drive, path_and_file = os.path.splitdrive(dir_name)

View File

@ -17,6 +17,7 @@ def setup_app(config):
logger.info('Starting uuidgen...')
return app
def main():
dir_name = os.path.dirname(__file__)
drive, path_and_file = os.path.splitdrive(dir_name)

View File

@ -48,7 +48,8 @@ class DataManager(BaseDataManager):
""" add a new region to the `region` table
add also the regions give meta_data and end_points to the `region_end_point` and
`region_meta_data` tables if given.
handle duplicate errors if raised"""
handle duplicate errors if raised
"""
try:
session = self._engine_facade.get_session()
with session.begin():
@ -115,7 +116,8 @@ class DataManager(BaseDataManager):
""" add a new region to the `region` table
add also the regions give meta_data and end_points to the `region_end_point` and
`region_meta_data` tables if given.
handle duplicate errors if raised"""
handle duplicate errors if raised
"""
try:
session = self._engine_facade.get_session()
with session.begin():

View File

@ -7,7 +7,8 @@ class BaseDataManagerTests(unittest.TestCase):
def test_base_data_manager_add_region_not_implemented(self):
""" Check if creating an instance and calling add_region
method fail"""
method fail
"""
with self.assertRaises(NotImplementedError):
BaseDataManager("", "", "").add_region('1', '2', '3', '4', '5', '6', '7',
'8', '9', '10', '11', '12', '13',
@ -15,30 +16,35 @@ class BaseDataManagerTests(unittest.TestCase):
def test_base_data_manager_get_regions_not_implemented(self):
""" Check if creating an instance and calling get_regions
method fail"""
method fail
"""
with self.assertRaises(NotImplementedError):
BaseDataManager("", "", "").get_regions('1', '2', '3')
def test_base_data_manager_get_all_regions_not_implemented(self):
""" Check if creating an instance and calling get_all_regions
method fail"""
method fail
"""
with self.assertRaises(NotImplementedError):
BaseDataManager("", "", "").get_all_regions()
def test_base_data_manager_add_group_not_implemented(self):
""" Check if creating an instance and calling add_group
method fail"""
method fail
"""
with self.assertRaises(NotImplementedError):
BaseDataManager("", "", "").add_group("1", "2", "3", "4")
def test_base_data_manager_get_group_not_implemented(self):
""" Check if creating an instance and calling get_group
method fail"""
method fail
"""
with self.assertRaises(NotImplementedError):
BaseDataManager("", "", "").get_group("1")
def test_base_data_manager_get_all_groups_not_implemented(self):
""" Check if creating an instance and calling get_all_groups
method fail"""
method fail
"""
with self.assertRaises(NotImplementedError):
BaseDataManager("", "", "").get_all_groups()

View File

@ -12,6 +12,7 @@ class StorageFactoryTests(unittest.TestCase):
@patch.object(data_manager, 'db_session')
def test_get_data_manager(self, conf_mock, db_session_mock):
""" Check the returned object from get_region_resource_id_status_connection
is instance of DataManager"""
is instance of DataManager
"""
obj = data_manager_factory.get_data_manager()
self.assertIsInstance(obj, DataManager)

View File

@ -53,11 +53,11 @@ logging = {
'class': 'logging.StreamHandler',
'formatter': 'color'
},
'logfile' : {
'logfile': {
'class': 'logging.FileHandler',
'filename' : '/home/pecanlogs.log',
'level' : 'DEBUG',
'formatter' : 'simple'
'filename': '/home/pecanlogs.log',
'level': 'DEBUG',
'formatter': 'simple'
}
},
'formatters': {

View File

@ -14,14 +14,14 @@ class ORD(object):
@expose()
def index(self):
return dict()
ord_notifier=root.OrdNotifier()
ord_notifier = root.OrdNotifier()
class RootOne(object):
@expose()
def index(self):
return dict()
ord=ORD()
ord = ORD()
class RootController(object):
@ -34,7 +34,6 @@ class RootController(object):
def index_get(self):
return 'hi'
def error(self, status):
try:
status = int(status)
@ -43,6 +42,6 @@ class RootController(object):
message = getattr(status_map.get(status), 'explanation', '')
return dict(status=status, message=message)
cat=CatalogController()
cat = CatalogController()
#customer=root.CreateNewCustomer()
v1=RootOne()
v1 = RootOne()

View File

@ -21,7 +21,8 @@ def setup_app(pecan_config):
or by running this file with python,
then the main method is called and starting pecan.
The method initializes components and return a WSGI application"""
The method initializes components and return a WSGI application
"""
init_sot()
init_audit()

View File

@ -90,7 +90,8 @@ def _notify(ord_url,
:return:
"""
# Prepare the request body
data_to_send = {'ord-notifier': {
data_to_send = {
'ord-notifier': {
'request-id': transaction_id,
'resource-id': resource_id,
'resource-type': resource_type,

View File

@ -7,6 +7,7 @@ from pecan import conf
logger = logging.getLogger(__name__)
def get_users_quotas(data, region):
"""get default or own region.
@ -46,8 +47,8 @@ def creat_final_yaml(title, description, resources, outputs):
def _create_metadata_yaml(alldata):
metadata ={}
metadata_items={}
metadata = {}
metadata_items = {}
for item in alldata['metadata']:
metadata_items.update(item)
metadata['tenant_metadata'] = {'type': 'OS::Keystone::Metadata\n',

View File

@ -22,23 +22,23 @@ def _properties(alldata, region):
protected = {0: False, 1: True}[alldata['protected']]
tenants = [tenant['customer_id'] for tenant in alldata['customers']]
return dict(
name = alldata['name'],
container_format = alldata["container_format"],
min_ram = alldata['min_ram'],
disk_format = alldata['disk_format'],
min_disk = alldata['min_disk'],
protected = protected,
copy_from = alldata["url"],
owner = alldata["owner"],
is_public = public,
tenants = str(tenants)
name=alldata['name'],
container_format=alldata["container_format"],
min_ram=alldata['min_ram'],
disk_format=alldata['disk_format'],
min_disk=alldata['min_disk'],
protected=protected,
copy_from=alldata["url"],
owner=alldata["owner"],
is_public=public,
tenants=str(tenants)
)
def _glanceimage(alldata, region):
return dict(
type = "OS::Glance::Image2",
properties = _properties(alldata, region)
type="OS::Glance::Image2",
properties=_properties(alldata, region)
)

View File

@ -1,7 +1,7 @@
from rds.storage.mysql.region_resource_id_status import Connection as RegionResourceIdStatusConnection
database = {
'url' : 'na'
'url': 'na'
}

View File

@ -32,6 +32,7 @@ class ResourceStatusRecord(Base):
resource_extra_metadata = relationship("ImageMetadData",
cascade="all, delete, delete-orphan")
class ImageMetadData(Base):
__tablename__ = 'image_metadata'
@ -164,7 +165,8 @@ class Connection(region_resource_id_status.Base):
""" This method filters all the records where resource_id is the given
resource_id and status is the given status.
for the matching records check if a time period elapsed and if so,
change the status to 'Error' and the timestamp to the given timestamp."""
change the status to 'Error' and the timestamp to the given timestamp.
"""
logger.debug("Get records filtered by resource_id={} "
"and status={}".format(resource_id,
status))

View File

@ -86,7 +86,7 @@ yaml_configs = {
}
# yaml configuration for create flavor
yaml_flavor_version='2014-10-16'
yaml_flavor_version = '2014-10-16'
# value of status to be blocked before creating any resource
block_by_status = "Submitted"

View File

@ -83,14 +83,14 @@ class TestCreateResource(FunctionalTest):
@patch.object(root.ResourceService, 'main', return_value="12345")
def test_update_resource_success(self, input):
updated =False
updated = False
"""test update resource as it succeed."""
response = self.app.put_json('/v1/rds/resources', good_data)
if 'updated' in response.json['customer']:
updated = True
assert response.json['customer']['id'] == '12345'
assert response.status_int == 201
assert updated == True
assert updated
@patch.object(root.ResourceService, 'main',
side_effect=Exception("unknown error"))
@ -178,7 +178,7 @@ good_data = {
"tracking_id": "uuid-12345"
}
}
}
}
flavor_data = {
"service_template": {
@ -208,7 +208,7 @@ flavor_data = {
"tracking_id": "uuid-12345"
}
}
}
}
image_data = {
"service_template": {

View File

@ -46,7 +46,7 @@ data = {
"error-code": "200",
"error-msg": "OK"
}
}
}
data_not_valid = {
"rds_listener": {
@ -61,4 +61,4 @@ data_not_valid = {
"error_code": "200",
"error_msg": "OK"
}
}
}

View File

@ -186,7 +186,7 @@ class MainTest(unittest.TestCase):
'gigi', '7', '')
self.fail('notify_ord() passed successfully (expected OrdNotFoundError)')
except ord_notifier.OrdNotFoundError as e:
self.assertEquals(e.message, 'ORD of LCP %s not found' % (
self.assertEqual(e.message, 'ORD of LCP %s not found' % (
'gigi', ))
#@patch.object(ord_notifier.audit, 'audit')

View File

@ -226,7 +226,6 @@ class CreateResource(unittest.TestCase):
# 'flavor', 'delete')
# self.assertEqual('uuid-uuid-uuid-uuid', resource_id)
# @patch.object(ResourceService.regionResourceIdStatus, 'add_status',
# return_value=None)
# @patch.object(ResourceService.yaml_customer_builder, 'yamlbuilder',
@ -248,7 +247,6 @@ class CreateResource(unittest.TestCase):
# resource_id = ResourceService.main(jsondata, uuid,
# 'customer', 'modify')
# @patch.object(ResourceService.regionResourceIdStatus, 'add_status',
# return_value=None)
# @patch.object(ResourceService.yaml_image_builder, 'yamlbuilder',
@ -270,13 +268,11 @@ class CreateResource(unittest.TestCase):
# resource_id = ResourceService.main(json_data_image, uuid,
# 'image', 'modify')
def test_get_inputs_from_resource_type(self):
input_data = ResourceService._get_inputs_from_resource_type(jsondata,
'customer',
'uuid-12345')
assert ( input_data.__dict__ == input_data_resource )
assert (input_data.__dict__ == input_data_resource)
def test_get_inputs_from_resource_type_image(self):
input_data = ResourceService._get_inputs_from_resource_type(json_data_image,
@ -284,7 +280,6 @@ class CreateResource(unittest.TestCase):
'uuid-12345')
assert (input_data.__dict__ == expected_image_input_data)
def test_unknown_resource_type(self):
with self.assertRaises(ResourceService.ErrorMesage):
input_data = ResourceService._get_inputs_from_resource_type(jsondata,
@ -292,7 +287,6 @@ class CreateResource(unittest.TestCase):
'uuid-12345')
jsondata = {
"uuid": "1e24981a-fa51-11e5-86aa-5e5517507c66", "default_region":
{
@ -309,8 +303,7 @@ jsondata = {
"snapshots": "10",
"volumes": "10"
},
"network":
{
"network":{
"router": "10",
"floatingip": "10",
"port": "10",
@ -400,68 +393,139 @@ jsondata = {
"name": "welcome_man"
}
flavorjsondata = {"status": "complete", "profile": "P2", "regions":
[{"name": "North1","action": "create"}, {"name": "North2","action": "delete"
}], "description": "First flavor for AMAR",
"ram": 64, "visibility": "public", "extra_specs": {
"key1": "value1", "key2": "value2", "keyx": "valuex"},
flavorjsondata = {
"status": "complete",
"profile": "P2",
"regions": [
{
"name": "North1",
"action": "create"
},
{
"name": "North2",
"action": "delete"
}
],
"description": "First flavor for AMAR",
"ram": 64,
"visibility": "public",
"extra_specs": {
"key1": "value1",
"key2": "value2",
"keyx": "valuex"
},
"vcpus": 2,
"swap": 0, "tenants": [{"tenant_id": "abcd-efgh-ijkl-4567"},
{"tenant_id": "abcd-efgh-ijkl-4567"
}],
"disk": 512, "empheral": 1, "id": "uuid-uuid-uuid-uuid",
"name": "Nice Flavor"}
"swap": 0,
"tenants": [
{
"tenant_id": "abcd-efgh-ijkl-4567"
},
{
"tenant_id": "abcd-efgh-ijkl-4567"
}
],
"disk": 512,
"empheral": 1,
"id": "uuid-uuid-uuid-uuid",
"name": "Nice Flavor"
}
json_data = {'uuid': '1e24981a-fa51-11e5-86aa-5e5517507c66',
'default_region': {'users': [{'id': 'userId1zzzz',
'roles': ['adminzzzz',
'otherzzzzz'
json_data = {
"uuid": "1e24981a-fa51-11e5-86aa-5e5517507c66",
"default_region": {
"users": [
{
"id": "userId1zzzz",
"roles": [
"adminzzzz",
"otherzzzzz"
]
},
{'id': 'userId2zzz',
'roles': ['storagezzzzz'
{
"id": "userId2zzz",
"roles": [
"storagezzzzz"
]
}
],
'name': 'regionnamezzzz',
"name": "regionnamezzzz",
"action": "create",
'quotas': [{'storage': {
'gigabytes': '111',
'volumes': '111',
'snapshots': '111'},
'compute': {'instances': '111',
'ram': '111',
'keypairs': '111',
'injected_files': '111'
"quotas": [
{
"storage": {
"gigabytes": "111",
"volumes": "111",
"snapshots": "111"
},
'network': {'port': '111',
'router': '111',
'subnet': '111',
'network': '111',
'floatingip': '111'}}]},
'description': 'this is a description', 'enabled': 1,
'regions': [{'users': [{'id': 'userId1',
'roles': ['admin', 'other']},
{'id': 'userId2',
'roles': ['storage']}],
'name': 'regionname', "action": "delete",
'quotas': []},
{'users': [], 'name': 'regionnametest',
"compute": {
"instances": "111",
"ram": "111",
"keypairs": "111",
"injected_files": "111"
},
"network": {
"port": "111",
"router": "111",
"subnet": "111",
"network": "111",
"floatingip": "111"
}
}
]
},
"description": "this is a description",
"enabled": 1,
"regions": [
{
"users": [
{
"id": "userId1",
"roles": [
"admin",
"other"
]
},
{
"id": "userId2",
"roles": [
"storage"
]
}
],
"name": "regionname",
"action": "delete",
"quotas": []
},
{
"users": [],
"name": "regionnametest",
"action": "modify",
'quotas': [{'storage': {'gigabytes': '10',
'volumes': '10',
'snapshots': '10'},
'compute': {'instances': '10',
'ram': '10',
'keypairs': '10',
'injected_files': '10'},
'network': {'port': '10',
'router': '10',
'subnet': '10',
'network': '10',
'floatingip': '10'}}]}],
'name': 'welcome_man'}
"quotas": [
{
"storage": {
"gigabytes": "10",
"volumes": "10",
"snapshots": "10"
},
"compute": {
"instances": "10",
"ram": "10",
"keypairs": "10",
"injected_files": "10"
},
"network": {
"port": "10",
"router": "10",
"subnet": "10",
"network": "10",
"floatingip": "10"
}
}
]
}
],
"name": "welcome_man"
}
target_list = [{'template_data': ['anystring'],
'operation': 'create',

View File

@ -64,7 +64,7 @@ class CreateResource(unittest.TestCase):
@patch.object(FlavorBuild, 'conf')
def test_create_flavor_yaml(self, mock_conf):
self.maxDiff=None
self.maxDiff = None
"""test valid dict to yaml output as expected."""
mock_conf.yaml_configs.flavor_yaml.yaml_version = '2015-1-1'
mock_conf.yaml_configs.flavor_yaml.yaml_args.rxtx_factor = 1

View File

@ -41,6 +41,7 @@ yaml_output = {'description': 'yaml file for region - North',
'heat_template_version': '2015-1-1',
'outputs': {'glance_image_id': {'value': {'get_resource': 'glance_image'}}}}
class CreateImage(unittest.TestCase):
"""class method image test."""

View File

@ -49,7 +49,8 @@ class BaseGitTests(unittest.TestCase):
def test_git_base_no_method_git_reset_changes_implemented(self):
""" Check if creating an instance and calling
git_reset_changes method fail"""
git_reset_changes method fail
"""
with self.assertRaises(NotImplementedError):
base_git = BaseGit()
base_git.git_reset_changes()

View File

@ -22,7 +22,7 @@ resource = {
"template_data": '4'
}
resource_delete= {
resource_delete = {
"operation": "delete",
"region_id": '1',
"resource_type": '2',
@ -125,7 +125,6 @@ class GitSoTTest(unittest.TestCase):
sot.save_resource_to_sot("t_id", "tk_id", [], "a_id", "u_id")
self.assertNotEqual(thread, threading.Thread.getName("main_thread"))
################################
# create_file_in_path #
################################
@ -196,7 +195,6 @@ class GitSoTTest(unittest.TestCase):
# sot.handle_file_operations([resource_delete, ], roll_list)
# self.assertEqual(len(roll_list), 1)
#############################
# write_data_to_file #
#############################
@ -272,8 +270,8 @@ class GitSoTTest(unittest.TestCase):
def test_git_sot_update_git_commit_faild(self):
"""Check update_git commit failed"""
git_impl = mock.MagicMock()
git_impl.git_upload_changes = mock.MagicMock(side_effect=
GitUploadError("Failed in upload"))
git_impl.git_upload_changes = mock.MagicMock(
side_effect=GitUploadError("Failed in upload"))
with self.assertRaises(GitUploadError):
sot.update_git(git_impl)
@ -284,8 +282,8 @@ class GitSoTTest(unittest.TestCase):
def test_git_sot_validate_git_faild(self):
"""Check validate_git failed"""
git_impl = mock.MagicMock()
git_impl.validate_git = mock.MagicMock(side_effect=
GitValidateError("Failed in upload"))
git_impl.validate_git = mock.MagicMock(
side_effect=GitValidateError("Failed in upload"))
try:
sot.validate_git(git_impl, lock)
except GitInitError:

View File

@ -14,14 +14,16 @@ class SoTFactoryTests(unittest.TestCase):
def test_get_sot_no_sot_type(self):
"""Check that a runtime error is raised if no git type
is available from config"""
is available from config
"""
sot_factory.sot_type = ""
with self.assertRaises(RuntimeError):
sot_factory.get_sot()
def test_get_sot_git_type(self):
""" Check that when 'git' type is provided the returned object
is instance of GiTSoT"""
is instance of GiTSoT
"""
sot_factory.sot_type = "git"
obj = sot_factory.get_sot()
self.assertIsInstance(obj, GitSoT)

View File

@ -71,7 +71,8 @@ class MysqlRegionResourceIdStatusTest(unittest.TestCase):
return_value=MyFacade(False, True))
def test_add_update_status_record_record_exist_sanity(self, mock_db_session):
"""Test that no exception is raised when calling add_update_status_record.
where record exist"""
where record exist
"""
my_connection = region_resource_id_status.Connection('url')
my_connection.add_update_status_record('timestamp',
'region',
@ -89,7 +90,8 @@ class MysqlRegionResourceIdStatusTest(unittest.TestCase):
return_value=MyFacade())
def test_add_update_status_record_record_not_exist_sanity(self, mock_db_session):
"""Test that no exception is raised when calling add_update_status_record.
where record does not exist"""
where record does not exist
"""
my_connection = region_resource_id_status.Connection('url')
my_connection.add_update_status_record('timestamp',
'region',

View File

@ -40,7 +40,7 @@ def _get_all_rms_regions():
def _validate_version(region, resource_type):
version = None
if 'ranger_agent' in region['version'].lower():
version = region['version'].lower().split('ranger_agent')[1].strip().split('.')
version = region['version'].lower().split('ranger-agent')[1].strip().split('.')
version = version[0] + '.' + ''.join(version[1:])
if not version or float(version) < 3:
return False
@ -71,3 +71,4 @@ def add_rms_status_to_regions(resource_regions, resource_type):
# if region not found in rms
region['rms_status'] = "region_not_found_in_rms"
return resource_regions

View File

@ -34,6 +34,6 @@ commands = oslo_debug_helper {posargs}
# E123, E125 skipped as they are invalid PEP-8.
show-source = True
ignore = E123,E125,H101,H104,H238,H401,H404,H405,H306,E901,E128,E226,E501,F401,F841,F841,W191,W391,E101,E121,E122,E126,E231,H233,H301,H303,H304,F403,F811,E401,H201,E265,E111,W292,E201,E127,H202,E251,H403,F821,E303,E225,H234,E712,E124,E131,E203,E202,E221,E271,E302
ignore = F821,H202,E125,H101,H104,H238,H401,H404,H405,H306,E901,E128,E226,E501,F401,F841,F841,W191,W391,E101,E121,E122,E126,E231,H233,H301,H303,H304,F403,F811,E401,H201,E265,E111,W292,E201
builtins = _
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build