From b35fdcc6aba6db0d4a22f7e1ee6a2900bdea49af Mon Sep 17 00:00:00 2001 From: Adrian Turjak Date: Thu, 17 Sep 2020 12:56:00 +1200 Subject: [PATCH] Reformat with updated version of black formatter Change-Id: I74aea5668c3027cff4d2f3ecb6de456e60bb6129 --- adjutant/actions/utils.py | 6 ++++- adjutant/actions/v1/projects.py | 11 ++++++-- adjutant/actions/v1/resources.py | 26 ++++++++++++++----- .../actions/v1/tests/test_misc_actions.py | 5 +++- .../actions/v1/tests/test_resource_actions.py | 4 ++- .../actions/v1/tests/test_user_actions.py | 13 ++++++++-- adjutant/actions/v1/users.py | 5 +++- adjutant/api/exception_handler.py | 3 +-- .../api/migrations/0005_auto_20190610_0209.py | 5 +++- .../api/migrations/0008_auto_20190610_0209.py | 6 ++++- adjutant/api/v1/openstack.py | 2 +- adjutant/api/v1/tests/test_api_admin.py | 3 +-- adjutant/api/v1/tests/test_api_openstack.py | 20 ++++++++------ adjutant/api/v1/views.py | 9 ++++++- adjutant/common/tests/fake_clients.py | 12 ++++++--- adjutant/config/identity.py | 13 ++++++++-- adjutant/config/quota.py | 6 ++++- adjutant/config/workflow.py | 8 ++++-- adjutant/notifications/v1/email.py | 3 ++- adjutant/settings.py | 20 +++++++++++--- adjutant/tasks/migrations/0001_initial.py | 4 ++- .../migrations/0002_auto_20190619_0613.py | 13 +++++++--- adjutant/tasks/v1/base.py | 7 ++--- adjutant/tasks/v1/utils.py | 6 ++++- setup.py | 3 ++- 25 files changed, 160 insertions(+), 53 deletions(-) diff --git a/adjutant/actions/utils.py b/adjutant/actions/utils.py index da900e2..eb2d6bc 100644 --- a/adjutant/actions/utils.py +++ b/adjutant/actions/utils.py @@ -71,7 +71,11 @@ def send_email(to_addresses, context, conf, task): } email = EmailMultiAlternatives( - conf["subject"], message, from_email, to_addresses, headers=headers, + conf["subject"], + message, + from_email, + to_addresses, + headers=headers, ) if html_template: diff --git a/adjutant/actions/v1/projects.py b/adjutant/actions/v1/projects.py index 2e2faf1..bdee05e 100644 --- a/adjutant/actions/v1/projects.py +++ b/adjutant/actions/v1/projects.py @@ -493,12 +493,19 @@ class AddDefaultUsersToProjectAction(BaseAction, ProjectMixin, UserMixin): return all_found def _pre_validate(self): - self.action.valid = validate_steps([self._validate_users,]) + self.action.valid = validate_steps( + [ + self._validate_users, + ] + ) self.action.save() def _validate(self): self.action.valid = validate_steps( - [self._validate_users, self._validate_project_id,] + [ + self._validate_users, + self._validate_project_id, + ] ) self.action.save() diff --git a/adjutant/actions/v1/resources.py b/adjutant/actions/v1/resources.py index 0a91774..a5c0f97 100644 --- a/adjutant/actions/v1/resources.py +++ b/adjutant/actions/v1/resources.py @@ -64,13 +64,16 @@ class NewDefaultNetworkAction(BaseAction, ProjectMixin): default="default_router", ), fields.StrConfig( - "public_network", help_text="ID of the public network.", + "public_network", + help_text="ID of the public network.", ), fields.StrConfig( - "subnet_cidr", help_text="CIDR for the default subnet.", + "subnet_cidr", + help_text="CIDR for the default subnet.", ), fields.ListConfig( - "dns_nameservers", help_text="DNS nameservers for the subnet.", + "dns_nameservers", + help_text="DNS nameservers for the subnet.", ), ], ), @@ -235,12 +238,19 @@ class NewProjectDefaultNetworkAction(NewDefaultNetworkAction): def _pre_validate(self): # Note: Don't check project here as it doesn't exist yet. - self.action.valid = validate_steps([self._validate_region,]) + self.action.valid = validate_steps( + [ + self._validate_region, + ] + ) self.action.save() def _validate(self): self.action.valid = validate_steps( - [self._validate_region, self._validate_project_id,] + [ + self._validate_region, + self._validate_project_id, + ] ) self.action.save() @@ -457,7 +467,11 @@ class SetProjectQuotaAction(UpdateProjectQuotasAction): def _validate(self): # Make sure the project id is valid and can be used - self.action.valid = validate_steps([self._validate_project_id,]) + self.action.valid = validate_steps( + [ + self._validate_project_id, + ] + ) self.action.save() def _prepare(self): diff --git a/adjutant/actions/v1/tests/test_misc_actions.py b/adjutant/actions/v1/tests/test_misc_actions.py index 29ae2c8..7048440 100644 --- a/adjutant/actions/v1/tests/test_misc_actions.py +++ b/adjutant/actions/v1/tests/test_misc_actions.py @@ -89,7 +89,10 @@ class MiscActionTests(AdjutantTestCase): it to become invalid or break. """ - task = Task.objects.create(keystone_user={}, task_type="edit_roles",) + task = Task.objects.create( + keystone_user={}, + task_type="edit_roles", + ) action = SendAdditionalEmailAction({}, task=task, order=1) diff --git a/adjutant/actions/v1/tests/test_resource_actions.py b/adjutant/actions/v1/tests/test_resource_actions.py index 3ebcc09..fcd0710 100644 --- a/adjutant/actions/v1/tests/test_resource_actions.py +++ b/adjutant/actions/v1/tests/test_resource_actions.py @@ -620,7 +620,9 @@ class QuotaActionTests(AdjutantTestCase): @conf_utils.modify_conf( CONF, operations={ - "adjutant.quota.sizes_ascending": [{"operation": "override", "value": []},], + "adjutant.quota.sizes_ascending": [ + {"operation": "override", "value": []}, + ], }, ) def test_update_quota_not_in_sizes_asc(self): diff --git a/adjutant/actions/v1/tests/test_user_actions.py b/adjutant/actions/v1/tests/test_user_actions.py index 409472f..3f105db 100644 --- a/adjutant/actions/v1/tests/test_user_actions.py +++ b/adjutant/actions/v1/tests/test_user_actions.py @@ -49,7 +49,11 @@ from adjutant.config import CONF "heat_stack_owner", "project_admin", ], - "project_mod": ["member", "heat_stack_owner", "project_mod",], + "project_mod": [ + "member", + "heat_stack_owner", + "project_mod", + ], }, }, ], @@ -859,7 +863,12 @@ class UserActionTests(AdjutantTestCase): "adjutant.identity.role_mapping": [ { "operation": "update", - "value": {"project_mod": ["member", "project_mod",],}, + "value": { + "project_mod": [ + "member", + "project_mod", + ], + }, }, ], }, diff --git a/adjutant/actions/v1/users.py b/adjutant/actions/v1/users.py index 5c79799..1db4406 100644 --- a/adjutant/actions/v1/users.py +++ b/adjutant/actions/v1/users.py @@ -435,7 +435,10 @@ class UpdateUserEmailAction(UserIdAction, UserMixin): def _validate(self): self.action.valid = validate_steps( - [self._validate_user, self._validate_email_not_in_use,] + [ + self._validate_user, + self._validate_email_not_in_use, + ] ) self.action.save() diff --git a/adjutant/api/exception_handler.py b/adjutant/api/exception_handler.py index 0b2fb40..5baf38b 100644 --- a/adjutant/api/exception_handler.py +++ b/adjutant/api/exception_handler.py @@ -27,8 +27,7 @@ LOG = getLogger("adjutant") def exception_handler(exc, context): - """Returns the response that should be used for any given exception. - """ + """Returns the response that should be used for any given exception.""" now = timezone.now() if isinstance(exc, Http404): exc = exceptions.NotFound() diff --git a/adjutant/api/migrations/0005_auto_20190610_0209.py b/adjutant/api/migrations/0005_auto_20190610_0209.py index eaf0016..f09ea1a 100644 --- a/adjutant/api/migrations/0005_auto_20190610_0209.py +++ b/adjutant/api/migrations/0005_auto_20190610_0209.py @@ -15,7 +15,10 @@ class Migration(migrations.Migration): operations = [ migrations.SeparateDatabaseAndState( database_operations=[ - migrations.AlterModelTable(name="task", table="tasks_task",), + migrations.AlterModelTable( + name="task", + table="tasks_task", + ), ], ), ] diff --git a/adjutant/api/migrations/0008_auto_20190610_0209.py b/adjutant/api/migrations/0008_auto_20190610_0209.py index bdbb774..34b2fa4 100644 --- a/adjutant/api/migrations/0008_auto_20190610_0209.py +++ b/adjutant/api/migrations/0008_auto_20190610_0209.py @@ -16,6 +16,10 @@ class Migration(migrations.Migration): operations = [ migrations.SeparateDatabaseAndState( - state_operations=[migrations.DeleteModel(name="Task",),], + state_operations=[ + migrations.DeleteModel( + name="Task", + ), + ], ), ] diff --git a/adjutant/api/v1/openstack.py b/adjutant/api/v1/openstack.py index ecb88f4..ea72acd 100644 --- a/adjutant/api/v1/openstack.py +++ b/adjutant/api/v1/openstack.py @@ -314,7 +314,7 @@ class UserRoles(BaseDelegateAPI): @utils.mod_or_admin def delete(self, args, **kwargs): - """ Revoke user roles to the current project. + """Revoke user roles to the current project. This only supports Active users """ diff --git a/adjutant/api/v1/tests/test_api_admin.py b/adjutant/api/v1/tests/test_api_admin.py index d4e254d..1fba538 100644 --- a/adjutant/api/v1/tests/test_api_admin.py +++ b/adjutant/api/v1/tests/test_api_admin.py @@ -1326,8 +1326,7 @@ class AdminAPITests(APITestCase): self.assertEqual(task, response.json()["tasks"][i]) def test_task_list_filter(self): - """ - """ + """""" project = fake_clients.FakeProject(name="test_project") setup_identity_cache(projects=[project]) diff --git a/adjutant/api/v1/tests/test_api_openstack.py b/adjutant/api/v1/tests/test_api_openstack.py index ee1ca69..ef32bd2 100644 --- a/adjutant/api/v1/tests/test_api_openstack.py +++ b/adjutant/api/v1/tests/test_api_openstack.py @@ -480,9 +480,9 @@ class QuotaAPITests(AdjutantAPITestCase): def test_update_quota_history(self): """ - Update the quota size of a project with a quota change recently - It should update the quota the first time but wait for admin approval - the second time + Update the quota size of a project with a quota change recently + It should update the quota the first time but wait for admin approval + the second time """ project = fake_clients.FakeProject(name="test_project", id="test_project_id") @@ -583,8 +583,8 @@ class QuotaAPITests(AdjutantAPITestCase): def test_update_quota_old_history(self): """ - Update the quota size of a project with a quota change 31 days ago - It should update the quota the first time without approval + Update the quota size of a project with a quota change 31 days ago + It should update the quota the first time without approval """ project = fake_clients.FakeProject(name="test_project", id="test_project_id") @@ -629,8 +629,8 @@ class QuotaAPITests(AdjutantAPITestCase): def test_update_quota_other_project_history(self): """ - Tests that a quota update to another project does not interfer - with the 30 days per project limit. + Tests that a quota update to another project does not interfer + with the 30 days per project limit. """ project = fake_clients.FakeProject(name="test_project", id="test_project_id") @@ -793,7 +793,11 @@ class QuotaAPITests(AdjutantAPITestCase): "security_groups": 0, "security_group_rules": 0, }, - "cinder": {"gigabytes": 0, "snapshots": 0, "volumes": 0,}, + "cinder": { + "gigabytes": 0, + "snapshots": 0, + "volumes": 0, + }, "neutron": { "floatingip": 0, "network": 0, diff --git a/adjutant/api/v1/views.py b/adjutant/api/v1/views.py index 522ef46..e8d0952 100644 --- a/adjutant/api/v1/views.py +++ b/adjutant/api/v1/views.py @@ -337,7 +337,14 @@ class TokenList(APIViewWithLogger): uuid = request.data.get("task", None) if uuid is None: return Response( - {"errors": {"task": ["This field is required.",]}}, status=400 + { + "errors": { + "task": [ + "This field is required.", + ] + } + }, + status=400, ) try: # TODO(adriant): better handle this bit of incode policy diff --git a/adjutant/common/tests/fake_clients.py b/adjutant/common/tests/fake_clients.py index ebdb514..10abfa9 100644 --- a/adjutant/common/tests/fake_clients.py +++ b/adjutant/common/tests/fake_clients.py @@ -159,7 +159,9 @@ def setup_identity_cache( "new_role_assignments": [], "roles": {r.id: r for r in roles}, "regions": {"RegionOne": region_one, "RegionTwo": region_two}, - "domains": {default_domain.id: default_domain,}, + "domains": { + default_domain.id: default_domain, + }, "credentials": credentials, } @@ -345,7 +347,9 @@ class FakeManager(object): if inherited: scope["OS-INHERIT:inherited_to"] = "projects" role_assignment = FakeRoleAssignment( - scope=scope, role={"name": role.name}, user={"id": user.id}, + scope=scope, + role={"name": role.name}, + user={"id": user.id}, ) return role_assignment @@ -773,8 +777,8 @@ class FakeCinderClient(FakeOpenstackClient): class FakeResource(object): - """ Stub class to represent an individual instance of a volume or - snapshot """ + """Stub class to represent an individual instance of a volume or + snapshot""" def __init__(self, size): self.size = size diff --git a/adjutant/config/identity.py b/adjutant/config/identity.py index 1472f4d..a8a9306 100644 --- a/adjutant/config/identity.py +++ b/adjutant/config/identity.py @@ -50,14 +50,23 @@ config_group.register_child_config( check_value_type=True, is_json=True, default={ - "admin": ["project_admin", "project_mod", "heat_stack_owner", "member",], + "admin": [ + "project_admin", + "project_mod", + "heat_stack_owner", + "member", + ], "project_admin": [ "project_admin", "project_mod", "heat_stack_owner", "member", ], - "project_mod": ["project_mod", "heat_stack_owner", "member",], + "project_mod": [ + "project_mod", + "heat_stack_owner", + "member", + ], }, test_default={ "admin": ["project_admin", "project_mod", "member", "heat_stack_owner"], diff --git a/adjutant/config/quota.py b/adjutant/config/quota.py index 2470537..32f7c52 100644 --- a/adjutant/config/quota.py +++ b/adjutant/config/quota.py @@ -32,7 +32,11 @@ DEFAULT_QUOTA_SIZES = { "security_groups": 20, "security_group_rules": 100, }, - "cinder": {"gigabytes": 5000, "snapshots": 50, "volumes": 20,}, + "cinder": { + "gigabytes": 5000, + "snapshots": 50, + "volumes": 20, + }, "neutron": { "floatingip": 10, "network": 3, diff --git a/adjutant/config/workflow.py b/adjutant/config/workflow.py index 16ec999..438a6f8 100644 --- a/adjutant/config/workflow.py +++ b/adjutant/config/workflow.py @@ -126,7 +126,9 @@ _notifications_defaults_group.register_child_config( "standard_handlers", help_text="Handlers to use for standard notifications.", required=True, - default=["EmailNotification",], + default=[ + "EmailNotification", + ], ) ) _notifications_defaults_group.register_child_config( @@ -134,7 +136,9 @@ _notifications_defaults_group.register_child_config( "error_handlers", help_text="Handlers to use for error notifications.", required=True, - default=["EmailNotification",], + default=[ + "EmailNotification", + ], ) ) _notifications_defaults_group.register_child_config( diff --git a/adjutant/notifications/v1/email.py b/adjutant/notifications/v1/email.py index dfbc7ca..f094fd8 100644 --- a/adjutant/notifications/v1/email.py +++ b/adjutant/notifications/v1/email.py @@ -61,7 +61,8 @@ class EmailNotification(base.BaseNotificationHandler): default="notification.txt", ), fields.StrConfig( - "html_template", help_text="Email html template for this notification.", + "html_template", + help_text="Email html template for this notification.", ), ] ) diff --git a/adjutant/settings.py b/adjutant/settings.py index 7e5c62c..d0bbbfc 100644 --- a/adjutant/settings.py +++ b/adjutant/settings.py @@ -94,8 +94,12 @@ AUTHENTICATION_BACKENDS = [] REST_FRAMEWORK = { "EXCEPTION_HANDLER": "adjutant.api.exception_handler.exception_handler", - "DEFAULT_RENDERER_CLASSES": ["rest_framework.renderers.JSONRenderer",], - "DEFAULT_PARSER_CLASSES": ["rest_framework.parsers.JSONParser",], + "DEFAULT_RENDERER_CLASSES": [ + "rest_framework.renderers.JSONRenderer", + ], + "DEFAULT_PARSER_CLASSES": [ + "rest_framework.parsers.JSONParser", + ], "DEFAULT_PERMISSION_CLASSES": [], } @@ -131,8 +135,16 @@ else: }, }, "loggers": { - "adjutant": {"handlers": ["file"], "level": "INFO", "propagate": False,}, - "django": {"handlers": ["file"], "level": "INFO", "propagate": False,}, + "adjutant": { + "handlers": ["file"], + "level": "INFO", + "propagate": False, + }, + "django": { + "handlers": ["file"], + "level": "INFO", + "propagate": False, + }, "keystonemiddleware": { "handlers": ["file"], "level": "INFO", diff --git a/adjutant/tasks/migrations/0001_initial.py b/adjutant/tasks/migrations/0001_initial.py index 05c3463..b378381 100644 --- a/adjutant/tasks/migrations/0001_initial.py +++ b/adjutant/tasks/migrations/0001_initial.py @@ -54,7 +54,9 @@ class Migration(migrations.Migration): ("approved_on", models.DateTimeField(null=True)), ("completed_on", models.DateTimeField(null=True)), ], - options={"indexes": [],}, + options={ + "indexes": [], + }, ), ], ), diff --git a/adjutant/tasks/migrations/0002_auto_20190619_0613.py b/adjutant/tasks/migrations/0002_auto_20190619_0613.py index dce8e0d..ea64afa 100644 --- a/adjutant/tasks/migrations/0002_auto_20190619_0613.py +++ b/adjutant/tasks/migrations/0002_auto_20190619_0613.py @@ -12,7 +12,10 @@ class Migration(migrations.Migration): ] operations = [ - migrations.RemoveField(model_name="task", name="ip_address",), + migrations.RemoveField( + model_name="task", + name="ip_address", + ), migrations.AddField( model_name="task", name="task_notes", @@ -34,7 +37,9 @@ class Migration(migrations.Migration): field=models.BooleanField(default=False), ), migrations.AlterField( - model_name="task", name="hash_key", field=models.CharField(max_length=64), + model_name="task", + name="hash_key", + field=models.CharField(max_length=64), ), migrations.AlterField( model_name="task", @@ -42,7 +47,9 @@ class Migration(migrations.Migration): field=models.CharField(max_length=64, null=True), ), migrations.AlterField( - model_name="task", name="task_type", field=models.CharField(max_length=100), + model_name="task", + name="task_type", + field=models.CharField(max_length=100), ), migrations.AddIndex( model_name="task", diff --git a/adjutant/tasks/v1/base.py b/adjutant/tasks/v1/base.py index f02110e..98ff360 100644 --- a/adjutant/tasks/v1/base.py +++ b/adjutant/tasks/v1/base.py @@ -75,7 +75,9 @@ def make_task_config(task_class): default=task_class.email_config or {}, sample_default={ "initial": None, - "token": {"subject": "Some custom subject",}, + "token": { + "subject": "Some custom subject", + }, }, ) ) @@ -424,8 +426,7 @@ class BaseTask(object): create_notification(self.task, notes) def approve(self, approved_by="system"): - """Run the approve stage for all the actions. - """ + """Run the approve stage for all the actions.""" self.confirm_state(completed=False, cancelled=False) diff --git a/adjutant/tasks/v1/utils.py b/adjutant/tasks/v1/utils.py index 03ea273..f418ea4 100644 --- a/adjutant/tasks/v1/utils.py +++ b/adjutant/tasks/v1/utils.py @@ -122,7 +122,11 @@ def send_stage_email(task, email_conf, token=None): } email = EmailMultiAlternatives( - email_conf["subject"], message, from_email, [emails.pop()], headers=headers, + email_conf["subject"], + message, + from_email, + [emails.pop()], + headers=headers, ) if html_template: diff --git a/setup.py b/setup.py index 6e30c43..63cb1e6 100644 --- a/setup.py +++ b/setup.py @@ -15,5 +15,6 @@ from setuptools import setup setup( - setup_requires=["pbr"], pbr=True, + setup_requires=["pbr"], + pbr=True, )