From a1b34c611e0c3f2d649908974689d408cb88c476 Mon Sep 17 00:00:00 2001 From: Nikolay Starodubtsev Date: Thu, 3 Sep 2015 14:28:11 +0300 Subject: [PATCH] Fix pylint errors 'unused variable' partially blueprint reduce-pylint-warnings Change-Id: Iaf0b4e919474db513fe18110f8bf9404df2fb5dd --- murano/api/v1/cloudfoundry/cfapi.py | 8 +++---- murano/common/utils.py | 2 +- murano/dsl/dsl_exception.py | 2 +- murano/dsl/macros.py | 4 ++-- murano/dsl/murano_class.py | 2 +- murano/packages/hot_package.py | 4 ++-- murano/packages/package.py | 2 +- murano/tests/functional/api/base.py | 9 ++++---- .../functional/api/v1/test_env_templates.py | 4 ++-- murano/tests/unit/api/cmd/test_test_runner.py | 19 ++++++++-------- murano/tests/unit/api/v1/test_catalog.py | 22 +++++++++---------- murano/tests/unit/db/test_catalog.py | 12 +++++----- .../dsl/foundation/test_package_loader.py | 2 +- 13 files changed, 45 insertions(+), 47 deletions(-) diff --git a/murano/api/v1/cloudfoundry/cfapi.py b/murano/api/v1/cloudfoundry/cfapi.py index b1f809a2..d62d0a96 100644 --- a/murano/api/v1/cloudfoundry/cfapi.py +++ b/murano/api/v1/cloudfoundry/cfapi.py @@ -93,7 +93,7 @@ class Controller(object): return None def list(self, req): - user, passwd, keystone = self._check_auth(req) + user, _, keystone = self._check_auth(req) # Once we get here we were authorized by keystone token = keystone.auth_token @@ -144,7 +144,7 @@ class Controller(object): # Now as we have all parameters we can try to auth user in actual # tenant - user, passwd, keystone = self._check_auth(req, tenant) + user, _, keystone = self._check_auth(req, tenant) # Once we get here we were authorized by keystone token = keystone.auth_token m_cli = muranoclient(token) @@ -198,7 +198,7 @@ class Controller(object): service_id = service.service_id environment_id = service.environment_id tenant = service.tenant - user, passwd, keystone = self._check_auth(req, tenant) + _, _, keystone = self._check_auth(req, tenant) # Once we get here we were authorized by keystone token = keystone.auth_token m_cli = muranoclient(token) @@ -227,7 +227,7 @@ class Controller(object): service_id = db_service.service_id environment_id = db_service.environment_id tenant = db_service.tenant - user, passwd, keystone = self._check_auth(req, tenant) + _, _, keystone = self._check_auth(req, tenant) # Once we get here we were authorized by keystone token = keystone.auth_token m_cli = muranoclient(token) diff --git a/murano/common/utils.py b/murano/common/utils.py index d953e251..785de01b 100644 --- a/murano/common/utils.py +++ b/murano/common/utils.py @@ -200,7 +200,7 @@ def build_entity_map(value): if isinstance(value, types.DictionaryType): if '?' in value and 'id' in value['?']: id_map[value['?']['id']] = value - for k, v in value.iteritems(): + for v in value.itervalues(): build_entity_map_recursive(v, id_map) if isinstance(value, types.ListType): for item in value: diff --git a/murano/dsl/dsl_exception.py b/murano/dsl/dsl_exception.py index 7f3d0196..2262b668 100644 --- a/murano/dsl/dsl_exception.py +++ b/murano/dsl/dsl_exception.py @@ -58,7 +58,7 @@ class MuranoPlException(Exception): result = MuranoPlException( names, str(exception), stacktrace) - exc_type, exc_value, exc_traceback = sys.exc_info() + _, _, exc_traceback = sys.exc_info() result.original_exception = exception result.original_traceback = exc_traceback return result diff --git a/murano/dsl/macros.py b/murano/dsl/macros.py index 3ccab976..30a0eabd 100644 --- a/murano/dsl/macros.py +++ b/murano/dsl/macros.py @@ -180,7 +180,7 @@ class RepeatMacro(expressions.DslExpression): def execute(self, context): count = helpers.evaluate(self._count, context) - for t in range(0, count): + for _ in range(0, count): try: self._code.execute(context) except exceptions.BreakException: @@ -214,7 +214,7 @@ class SwitchMacro(expressions.DslExpression): raise exceptions.DslSyntaxError( 'Switch value must be of dictionary type') self._switch = Switch - for key, value in self._switch.iteritems(): + for key in self._switch.iterkeys(): if not isinstance(key, (yaql_expression.YaqlExpression, types.BooleanType)): raise exceptions.DslSyntaxError( diff --git a/murano/dsl/murano_class.py b/murano/dsl/murano_class.py index 3a333b58..f1b82d99 100644 --- a/murano/dsl/murano_class.py +++ b/murano/dsl/murano_class.py @@ -275,7 +275,7 @@ class MuranoClass(dsl_types.MuranoClass): while i < len(versions_list): package1, requirement1 = versions_list[i] dst_package = None - for j, (package2, requirement2) in enumerate(versions_list): + for j, (package2, _) in enumerate(versions_list): if i == j: continue if package2.version in requirement1 and ( diff --git a/murano/packages/hot_package.py b/murano/packages/hot_package.py index a7d4ae0f..ed8f6774 100644 --- a/murano/packages/hot_package.py +++ b/murano/packages/hot_package.py @@ -172,7 +172,7 @@ class HotPackage(package_base.PackageBase): @staticmethod def _translate_outputs(hot): result = {} - for key, value in (hot.get('outputs') or {}).items(): + for key in (hot.get('outputs') or {}).keys(): result[key] = { "Contract": YAQL("$.string()"), "Usage": "Out" @@ -259,7 +259,7 @@ class HotPackage(package_base.PackageBase): hot_env = YAQL("$.hotEnvironment") copy_outputs = [] - for key, value in (hot.get('outputs') or {}).items(): + for key in (hot.get('outputs') or {}).keys(): copy_outputs.append({YAQL('$.' + key): YAQL('$outputs.' + key)}) deploy = [ diff --git a/murano/packages/package.py b/murano/packages/package.py index 4dfc71d3..9af68182 100644 --- a/murano/packages/package.py +++ b/murano/packages/package.py @@ -111,7 +111,7 @@ class Package(object): def _zip_dir(path, zip_file): - for root, dirs, files in os.walk(path): + for root, _, files in os.walk(path): for f in files: abs_path = os.path.join(root, f) relative_path = os.path.relpath(abs_path, path) diff --git a/murano/tests/functional/api/base.py b/murano/tests/functional/api/base.py index 238dfbd6..37183679 100644 --- a/murano/tests/functional/api/base.py +++ b/murano/tests/functional/api/base.py @@ -106,8 +106,7 @@ class MuranoClient(rest_client.RestClient): def deploy_session(self, environment_id, session_id): post_body = None url = 'v1/environments/{0}/sessions/{1}/deploy' - resp, body = self.post(url.format(environment_id, session_id), - post_body) + resp, _ = self.post(url.format(environment_id, session_id), post_body) return resp @@ -283,13 +282,13 @@ class MuranoClient(rest_client.RestClient): def delete_app_in_env_template(self, env_template_name): """Delete an application in an environment template.""" - resp, body = self.delete('v1/templates/{0}/services/{1}'. - format(env_template_name, 'ID')) + resp, _ = self.delete('v1/templates/{0}/services/{1}'. + format(env_template_name, 'ID')) return resp def delete_env_template(self, env_template_id): """Check the deletion of an environment template.""" - resp, body = self.delete('v1/templates/{0}'.format(env_template_id)) + resp, _ = self.delete('v1/templates/{0}'.format(env_template_id)) return resp def get_env_template(self, env_template_id): diff --git a/murano/tests/functional/api/v1/test_env_templates.py b/murano/tests/functional/api/v1/test_env_templates.py index eb4e6379..8c29d9f0 100644 --- a/murano/tests/functional/api/v1/test_env_templates.py +++ b/murano/tests/functional/api/v1/test_env_templates.py @@ -153,7 +153,7 @@ class TestEnvTemplate(base.TestCase): @attr(type='negative') def test_double_delete_env_template(self): """Check the deletion of an wrong environment template request.""" - resp, env_template = self.client.create_env_template('test_env_temp') + _, env_template = self.client.create_env_template('test_env_temp') self.client.delete_env_template(env_template['id']) @@ -165,7 +165,7 @@ class TestEnvTemplate(base.TestCase): @attr(type='negative') def test_get_deleted_env_template(self): """Check the deletion of an wrong environment template request.""" - resp, env_template = self.client.create_env_template('test_env_temp') + _, env_template = self.client.create_env_template('test_env_temp') self.client.delete_env_template(env_template['id']) diff --git a/murano/tests/unit/api/cmd/test_test_runner.py b/murano/tests/unit/api/cmd/test_test_runner.py index 7807330e..8b875ed8 100644 --- a/murano/tests/unit/api/cmd/test_test_runner.py +++ b/murano/tests/unit/api/cmd/test_test_runner.py @@ -80,7 +80,7 @@ class TestCaseShell(testtools.TestCase): return (stdout, stderr) def test_help(self): - stdout, stderr = self.shell('--help') + stdout, _ = self.shell('--help') usage = """usage: murano-test-runner [-h] [-v] [--config-file CONFIG_FILE] [--os-auth-url OS_AUTH_URL] [--os-username OS_USERNAME] @@ -96,13 +96,12 @@ class TestCaseShell(testtools.TestCase): importutils.import_module('keystonemiddleware.auth_token') self.override_config('admin_user', 'new_value', 'keystone_authtoken') - stdout, stderr = self.shell( - '-p io.murano.test.MyTest1 io.murano.test.MyTest2') + self.shell('-p io.murano.test.MyTest1 io.murano.test.MyTest2') mock_client.assert_has_calls([mock.call(**self.auth_params)]) def test_package_all_tests(self): - stdout, stderr = self.shell('-p io.murano.test.MyTest1') + _, stderr = self.shell('-p io.murano.test.MyTest1') # NOTE(efedorova): May be, there is a problem with test-runner, since # all logs are passed to stderr self.assertIn('io.murano.test.MyTest1.testSimple1.....OK', stderr) @@ -112,7 +111,7 @@ class TestCaseShell(testtools.TestCase): self.assertNotIn('thisIsNotAtestMethod', stderr) def test_package_by_class(self): - stdout, stderr = self.shell( + _, stderr = self.shell( '-p io.murano.test.MyTest1 io.murano.test.MyTest2') self.assertNotIn('io.murano.test.MyTest1.testSimple1.....OK', stderr) @@ -121,7 +120,7 @@ class TestCaseShell(testtools.TestCase): self.assertIn('io.murano.test.MyTest2.testSimple2.....OK', stderr) def test_package_by_test_name(self): - stdout, stderr = self.shell( + _, stderr = self.shell( '-p io.murano.test.MyTest1 testSimple1') self.assertIn('io.murano.test.MyTest1.testSimple1.....OK', stderr) @@ -130,7 +129,7 @@ class TestCaseShell(testtools.TestCase): self.assertNotIn('io.murano.test.MyTest2.testSimple2.....OK', stderr) def test_package_by_test_and_class_name(self): - stdout, stderr = self.shell( + _, stderr = self.shell( '-p io.murano.test.MyTest1 io.murano.test.MyTest2.testSimple1') self.assertNotIn('io.murano.test.MyTest1.testSimple1.....OK', stderr) @@ -139,17 +138,17 @@ class TestCaseShell(testtools.TestCase): self.assertNotIn('io.murano.test.MyTest2.testSimple2.....OK', stderr) def test_service_methods(self): - stdout, stderr = self.shell( + _, stderr = self.shell( '-p io.murano.test.MyTest1 io.murano.test.MyTest1.testSimple1') self.assertIn('Executing: io.murano.test.MyTest1.setUp', stderr) self.assertIn('Executing: io.murano.test.MyTest1.tearDown', stderr) def test_package_is_not_provided(self): - stdout, stderr = self.shell(exitcode=1) + _, stderr = self.shell(exitcode=1) self.assertEqual(stderr, 'ERROR: Package name is required parameter.') def test_wrong_parent(self): - stdout, stderr = self.shell( + _, stderr = self.shell( '-p io.murano.test.MyTest1 io.murano.test.MyTest3', exitcode=1) self.assertIn('Class io.murano.test.MyTest3 is not inherited from' ' io.murano.test.TestFixture. Skipping it.', stderr) diff --git a/murano/tests/unit/api/v1/test_catalog.py b/murano/tests/unit/api/v1/test_catalog.py index 4b014345..daa38bca 100644 --- a/murano/tests/unit/api/v1/test_catalog.py +++ b/murano/tests/unit/api/v1/test_catalog.py @@ -54,7 +54,7 @@ class TestCatalogApi(test_base.ControllerTest, test_base.MuranoApiTestCase): self._set_policy_rules( {'get_package': ''} ) - for i in range(7): + for dummy in range(7): self.expect_policy_check('get_package') pkg = self._add_pkg('test_tenant', type='Library') @@ -106,7 +106,7 @@ class TestCatalogApi(test_base.ControllerTest, test_base.MuranoApiTestCase): self._set_policy_rules( {'get_package': ''} ) - for i in range(7): + for dummy in range(7): self.expect_policy_check('get_package') pkg = self._add_pkg('test_tenant', type='Library') @@ -156,7 +156,7 @@ class TestCatalogApi(test_base.ControllerTest, test_base.MuranoApiTestCase): self._set_policy_rules( {'get_package': ''} ) - for i in range(9): + for dummy in range(9): self.expect_policy_check('get_package') result = self.controller.search(self._get('/v1/catalog/packages/')) @@ -238,7 +238,7 @@ class TestCatalogApi(test_base.ControllerTest, test_base.MuranoApiTestCase): self._set_policy_rules( {'get_package': '@'} ) - package_from_dir, package = self._test_package() + _, package = self._test_package() saved_package = db_catalog_api.package_upload(package, '') @@ -261,7 +261,7 @@ class TestCatalogApi(test_base.ControllerTest, test_base.MuranoApiTestCase): self._set_policy_rules( {'download_package': '@'} ) - package_from_dir, package = self._test_package() + _, package = self._test_package() saved_package = db_catalog_api.package_upload(package, '') @@ -278,7 +278,7 @@ class TestCatalogApi(test_base.ControllerTest, test_base.MuranoApiTestCase): def test_download_package_negative(self): - package_from_dir, package = self._test_package() + _, package = self._test_package() saved_package = db_catalog_api.package_upload(package, '') @@ -295,7 +295,7 @@ class TestCatalogApi(test_base.ControllerTest, test_base.MuranoApiTestCase): self._set_policy_rules( {'get_package': '@'} ) - package_from_dir, package = self._test_package() + _, package = self._test_package() saved_package = db_catalog_api.package_upload(package, '') @@ -311,7 +311,7 @@ class TestCatalogApi(test_base.ControllerTest, test_base.MuranoApiTestCase): self.assertEqual(200, result.status_code) def test_get_ui_definition_negative(self): - package_from_dir, package = self._test_package() + _, package = self._test_package() saved_package = db_catalog_api.package_upload(package, '') @@ -328,7 +328,7 @@ class TestCatalogApi(test_base.ControllerTest, test_base.MuranoApiTestCase): self._set_policy_rules( {'get_package': '@'} ) - package_from_dir, package = self._test_package() + _, package = self._test_package() saved_package = db_catalog_api.package_upload(package, '') @@ -345,7 +345,7 @@ class TestCatalogApi(test_base.ControllerTest, test_base.MuranoApiTestCase): self.assertEqual(package['logo'], result.body) def test_get_logo_negative(self): - package_from_dir, package = self._test_package() + _, package = self._test_package() saved_package = db_catalog_api.package_upload(package, '') @@ -375,7 +375,7 @@ class TestCatalogApi(test_base.ControllerTest, test_base.MuranoApiTestCase): file_obj_str = cStringIO.StringIO("This is some dummy data") file_obj = mock.MagicMock(cgi.FieldStorage) file_obj.file = file_obj_str - package_from_dir, package_metadata = self._test_package() + package_from_dir, _ = self._test_package() body = '''\ diff --git a/murano/tests/unit/db/test_catalog.py b/murano/tests/unit/db/test_catalog.py index a26b24ce..7615e1cd 100644 --- a/murano/tests/unit/db/test_catalog.py +++ b/murano/tests/unit/db/test_catalog.py @@ -64,7 +64,7 @@ class CatalogDBTestCase(base.MuranoWithDBTestCase): def test_order_by(self): pkgs = [] - for i in range(10): + for dummy in range(10): package = api.package_upload(self._stub_package( name=str(uuid.uuid4()), fully_qualified_name=str(uuid.uuid4())), self.tenant_id) @@ -86,12 +86,12 @@ class CatalogDBTestCase(base.MuranoWithDBTestCase): def test_order_by_compound(self): pkgs_a, pkgs_z = [], [] - for i in range(5): + for _ in range(5): package = api.package_upload(self._stub_package( name='z', fully_qualified_name=str(uuid.uuid4())), self.tenant_id) pkgs_z.append(package) - for i in range(5): + for _ in range(5): package = api.package_upload(self._stub_package( name='a', fully_qualified_name=str(uuid.uuid4())), self.tenant_id) @@ -113,7 +113,7 @@ class CatalogDBTestCase(base.MuranoWithDBTestCase): checking that package order is correct. """ pkgs = [] - for i in range(10): + for dummy in range(10): package = api.package_upload(self._stub_package( name=str(uuid.uuid4()), fully_qualified_name=str(uuid.uuid4())), self.tenant_id) @@ -154,7 +154,7 @@ class CatalogDBTestCase(base.MuranoWithDBTestCase): """ pkgs = [] - for i in range(10): + for dummy in range(10): package = api.package_upload(self._stub_package( name=str(uuid.uuid4()), fully_qualified_name=str(uuid.uuid4())), self.tenant_id) @@ -188,7 +188,7 @@ class CatalogDBTestCase(base.MuranoWithDBTestCase): """ # TODO(kzaitsev): fix https://bugs.launchpad.net/murano/+bug/1448782 - for i in range(10): + for dummy in range(10): api.package_upload(self._stub_package( fully_qualified_name=str(uuid.uuid4())), self.tenant_id) res = api.package_search({}, self.context, limit=4) diff --git a/murano/tests/unit/dsl/foundation/test_package_loader.py b/murano/tests/unit/dsl/foundation/test_package_loader.py index ee1773b8..5dc341b4 100644 --- a/murano/tests/unit/dsl/foundation/test_package_loader.py +++ b/murano/tests/unit/dsl/foundation/test_package_loader.py @@ -75,7 +75,7 @@ class TestPackageLoader(package_loader.MuranoPackageLoader): def _build_index(self, directory): yamls = [os.path.join(dirpath, f) - for dirpath, dirnames, files in os.walk(directory) + for dirpath, _, files in os.walk(directory) for f in fnmatch.filter(files, '*.yaml')] for class_def_file in yamls: self._load_class(class_def_file)