Reformat with updated version of black formatter

Change-Id: I74aea5668c3027cff4d2f3ecb6de456e60bb6129
This commit is contained in:
Adrian Turjak 2020-09-17 12:56:00 +12:00
parent 9dd1f3a302
commit b35fdcc6ab
25 changed files with 160 additions and 53 deletions

View File

@ -71,7 +71,11 @@ def send_email(to_addresses, context, conf, task):
} }
email = EmailMultiAlternatives( email = EmailMultiAlternatives(
conf["subject"], message, from_email, to_addresses, headers=headers, conf["subject"],
message,
from_email,
to_addresses,
headers=headers,
) )
if html_template: if html_template:

View File

@ -493,12 +493,19 @@ class AddDefaultUsersToProjectAction(BaseAction, ProjectMixin, UserMixin):
return all_found return all_found
def _pre_validate(self): def _pre_validate(self):
self.action.valid = validate_steps([self._validate_users,]) self.action.valid = validate_steps(
[
self._validate_users,
]
)
self.action.save() self.action.save()
def _validate(self): def _validate(self):
self.action.valid = validate_steps( self.action.valid = validate_steps(
[self._validate_users, self._validate_project_id,] [
self._validate_users,
self._validate_project_id,
]
) )
self.action.save() self.action.save()

View File

@ -64,13 +64,16 @@ class NewDefaultNetworkAction(BaseAction, ProjectMixin):
default="default_router", default="default_router",
), ),
fields.StrConfig( fields.StrConfig(
"public_network", help_text="ID of the public network.", "public_network",
help_text="ID of the public network.",
), ),
fields.StrConfig( fields.StrConfig(
"subnet_cidr", help_text="CIDR for the default subnet.", "subnet_cidr",
help_text="CIDR for the default subnet.",
), ),
fields.ListConfig( 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): def _pre_validate(self):
# Note: Don't check project here as it doesn't exist yet. # 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() self.action.save()
def _validate(self): def _validate(self):
self.action.valid = validate_steps( self.action.valid = validate_steps(
[self._validate_region, self._validate_project_id,] [
self._validate_region,
self._validate_project_id,
]
) )
self.action.save() self.action.save()
@ -457,7 +467,11 @@ class SetProjectQuotaAction(UpdateProjectQuotasAction):
def _validate(self): def _validate(self):
# Make sure the project id is valid and can be used # 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() self.action.save()
def _prepare(self): def _prepare(self):

View File

@ -89,7 +89,10 @@ class MiscActionTests(AdjutantTestCase):
it to become invalid or break. 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) action = SendAdditionalEmailAction({}, task=task, order=1)

View File

@ -620,7 +620,9 @@ class QuotaActionTests(AdjutantTestCase):
@conf_utils.modify_conf( @conf_utils.modify_conf(
CONF, CONF,
operations={ operations={
"adjutant.quota.sizes_ascending": [{"operation": "override", "value": []},], "adjutant.quota.sizes_ascending": [
{"operation": "override", "value": []},
],
}, },
) )
def test_update_quota_not_in_sizes_asc(self): def test_update_quota_not_in_sizes_asc(self):

View File

@ -49,7 +49,11 @@ from adjutant.config import CONF
"heat_stack_owner", "heat_stack_owner",
"project_admin", "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": [ "adjutant.identity.role_mapping": [
{ {
"operation": "update", "operation": "update",
"value": {"project_mod": ["member", "project_mod",],}, "value": {
"project_mod": [
"member",
"project_mod",
],
},
}, },
], ],
}, },

View File

@ -435,7 +435,10 @@ class UpdateUserEmailAction(UserIdAction, UserMixin):
def _validate(self): def _validate(self):
self.action.valid = validate_steps( 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() self.action.save()

View File

@ -27,8 +27,7 @@ LOG = getLogger("adjutant")
def exception_handler(exc, context): 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() now = timezone.now()
if isinstance(exc, Http404): if isinstance(exc, Http404):
exc = exceptions.NotFound() exc = exceptions.NotFound()

View File

@ -15,7 +15,10 @@ class Migration(migrations.Migration):
operations = [ operations = [
migrations.SeparateDatabaseAndState( migrations.SeparateDatabaseAndState(
database_operations=[ database_operations=[
migrations.AlterModelTable(name="task", table="tasks_task",), migrations.AlterModelTable(
name="task",
table="tasks_task",
),
], ],
), ),
] ]

View File

@ -16,6 +16,10 @@ class Migration(migrations.Migration):
operations = [ operations = [
migrations.SeparateDatabaseAndState( migrations.SeparateDatabaseAndState(
state_operations=[migrations.DeleteModel(name="Task",),], state_operations=[
migrations.DeleteModel(
name="Task",
),
],
), ),
] ]

View File

@ -314,7 +314,7 @@ class UserRoles(BaseDelegateAPI):
@utils.mod_or_admin @utils.mod_or_admin
def delete(self, args, **kwargs): def delete(self, args, **kwargs):
""" Revoke user roles to the current project. """Revoke user roles to the current project.
This only supports Active users This only supports Active users
""" """

View File

@ -1326,8 +1326,7 @@ class AdminAPITests(APITestCase):
self.assertEqual(task, response.json()["tasks"][i]) self.assertEqual(task, response.json()["tasks"][i])
def test_task_list_filter(self): def test_task_list_filter(self):
""" """"""
"""
project = fake_clients.FakeProject(name="test_project") project = fake_clients.FakeProject(name="test_project")
setup_identity_cache(projects=[project]) setup_identity_cache(projects=[project])

View File

@ -480,9 +480,9 @@ class QuotaAPITests(AdjutantAPITestCase):
def test_update_quota_history(self): def test_update_quota_history(self):
""" """
Update the quota size of a project with a quota change recently 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 It should update the quota the first time but wait for admin approval
the second time the second time
""" """
project = fake_clients.FakeProject(name="test_project", id="test_project_id") 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): def test_update_quota_old_history(self):
""" """
Update the quota size of a project with a quota change 31 days ago Update the quota size of a project with a quota change 31 days ago
It should update the quota the first time without approval It should update the quota the first time without approval
""" """
project = fake_clients.FakeProject(name="test_project", id="test_project_id") 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): def test_update_quota_other_project_history(self):
""" """
Tests that a quota update to another project does not interfer Tests that a quota update to another project does not interfer
with the 30 days per project limit. with the 30 days per project limit.
""" """
project = fake_clients.FakeProject(name="test_project", id="test_project_id") project = fake_clients.FakeProject(name="test_project", id="test_project_id")
@ -793,7 +793,11 @@ class QuotaAPITests(AdjutantAPITestCase):
"security_groups": 0, "security_groups": 0,
"security_group_rules": 0, "security_group_rules": 0,
}, },
"cinder": {"gigabytes": 0, "snapshots": 0, "volumes": 0,}, "cinder": {
"gigabytes": 0,
"snapshots": 0,
"volumes": 0,
},
"neutron": { "neutron": {
"floatingip": 0, "floatingip": 0,
"network": 0, "network": 0,

View File

@ -337,7 +337,14 @@ class TokenList(APIViewWithLogger):
uuid = request.data.get("task", None) uuid = request.data.get("task", None)
if uuid is None: if uuid is None:
return Response( return Response(
{"errors": {"task": ["This field is required.",]}}, status=400 {
"errors": {
"task": [
"This field is required.",
]
}
},
status=400,
) )
try: try:
# TODO(adriant): better handle this bit of incode policy # TODO(adriant): better handle this bit of incode policy

View File

@ -159,7 +159,9 @@ def setup_identity_cache(
"new_role_assignments": [], "new_role_assignments": [],
"roles": {r.id: r for r in roles}, "roles": {r.id: r for r in roles},
"regions": {"RegionOne": region_one, "RegionTwo": region_two}, "regions": {"RegionOne": region_one, "RegionTwo": region_two},
"domains": {default_domain.id: default_domain,}, "domains": {
default_domain.id: default_domain,
},
"credentials": credentials, "credentials": credentials,
} }
@ -345,7 +347,9 @@ class FakeManager(object):
if inherited: if inherited:
scope["OS-INHERIT:inherited_to"] = "projects" scope["OS-INHERIT:inherited_to"] = "projects"
role_assignment = FakeRoleAssignment( 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 return role_assignment
@ -773,8 +777,8 @@ class FakeCinderClient(FakeOpenstackClient):
class FakeResource(object): class FakeResource(object):
""" Stub class to represent an individual instance of a volume or """Stub class to represent an individual instance of a volume or
snapshot """ snapshot"""
def __init__(self, size): def __init__(self, size):
self.size = size self.size = size

View File

@ -50,14 +50,23 @@ config_group.register_child_config(
check_value_type=True, check_value_type=True,
is_json=True, is_json=True,
default={ default={
"admin": ["project_admin", "project_mod", "heat_stack_owner", "member",], "admin": [
"project_admin",
"project_mod",
"heat_stack_owner",
"member",
],
"project_admin": [ "project_admin": [
"project_admin", "project_admin",
"project_mod", "project_mod",
"heat_stack_owner", "heat_stack_owner",
"member", "member",
], ],
"project_mod": ["project_mod", "heat_stack_owner", "member",], "project_mod": [
"project_mod",
"heat_stack_owner",
"member",
],
}, },
test_default={ test_default={
"admin": ["project_admin", "project_mod", "member", "heat_stack_owner"], "admin": ["project_admin", "project_mod", "member", "heat_stack_owner"],

View File

@ -32,7 +32,11 @@ DEFAULT_QUOTA_SIZES = {
"security_groups": 20, "security_groups": 20,
"security_group_rules": 100, "security_group_rules": 100,
}, },
"cinder": {"gigabytes": 5000, "snapshots": 50, "volumes": 20,}, "cinder": {
"gigabytes": 5000,
"snapshots": 50,
"volumes": 20,
},
"neutron": { "neutron": {
"floatingip": 10, "floatingip": 10,
"network": 3, "network": 3,

View File

@ -126,7 +126,9 @@ _notifications_defaults_group.register_child_config(
"standard_handlers", "standard_handlers",
help_text="Handlers to use for standard notifications.", help_text="Handlers to use for standard notifications.",
required=True, required=True,
default=["EmailNotification",], default=[
"EmailNotification",
],
) )
) )
_notifications_defaults_group.register_child_config( _notifications_defaults_group.register_child_config(
@ -134,7 +136,9 @@ _notifications_defaults_group.register_child_config(
"error_handlers", "error_handlers",
help_text="Handlers to use for error notifications.", help_text="Handlers to use for error notifications.",
required=True, required=True,
default=["EmailNotification",], default=[
"EmailNotification",
],
) )
) )
_notifications_defaults_group.register_child_config( _notifications_defaults_group.register_child_config(

View File

@ -61,7 +61,8 @@ class EmailNotification(base.BaseNotificationHandler):
default="notification.txt", default="notification.txt",
), ),
fields.StrConfig( fields.StrConfig(
"html_template", help_text="Email html template for this notification.", "html_template",
help_text="Email html template for this notification.",
), ),
] ]
) )

View File

@ -94,8 +94,12 @@ AUTHENTICATION_BACKENDS = []
REST_FRAMEWORK = { REST_FRAMEWORK = {
"EXCEPTION_HANDLER": "adjutant.api.exception_handler.exception_handler", "EXCEPTION_HANDLER": "adjutant.api.exception_handler.exception_handler",
"DEFAULT_RENDERER_CLASSES": ["rest_framework.renderers.JSONRenderer",], "DEFAULT_RENDERER_CLASSES": [
"DEFAULT_PARSER_CLASSES": ["rest_framework.parsers.JSONParser",], "rest_framework.renderers.JSONRenderer",
],
"DEFAULT_PARSER_CLASSES": [
"rest_framework.parsers.JSONParser",
],
"DEFAULT_PERMISSION_CLASSES": [], "DEFAULT_PERMISSION_CLASSES": [],
} }
@ -131,8 +135,16 @@ else:
}, },
}, },
"loggers": { "loggers": {
"adjutant": {"handlers": ["file"], "level": "INFO", "propagate": False,}, "adjutant": {
"django": {"handlers": ["file"], "level": "INFO", "propagate": False,}, "handlers": ["file"],
"level": "INFO",
"propagate": False,
},
"django": {
"handlers": ["file"],
"level": "INFO",
"propagate": False,
},
"keystonemiddleware": { "keystonemiddleware": {
"handlers": ["file"], "handlers": ["file"],
"level": "INFO", "level": "INFO",

View File

@ -54,7 +54,9 @@ class Migration(migrations.Migration):
("approved_on", models.DateTimeField(null=True)), ("approved_on", models.DateTimeField(null=True)),
("completed_on", models.DateTimeField(null=True)), ("completed_on", models.DateTimeField(null=True)),
], ],
options={"indexes": [],}, options={
"indexes": [],
},
), ),
], ],
), ),

View File

@ -12,7 +12,10 @@ class Migration(migrations.Migration):
] ]
operations = [ operations = [
migrations.RemoveField(model_name="task", name="ip_address",), migrations.RemoveField(
model_name="task",
name="ip_address",
),
migrations.AddField( migrations.AddField(
model_name="task", model_name="task",
name="task_notes", name="task_notes",
@ -34,7 +37,9 @@ class Migration(migrations.Migration):
field=models.BooleanField(default=False), field=models.BooleanField(default=False),
), ),
migrations.AlterField( 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( migrations.AlterField(
model_name="task", model_name="task",
@ -42,7 +47,9 @@ class Migration(migrations.Migration):
field=models.CharField(max_length=64, null=True), field=models.CharField(max_length=64, null=True),
), ),
migrations.AlterField( 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( migrations.AddIndex(
model_name="task", model_name="task",

View File

@ -75,7 +75,9 @@ def make_task_config(task_class):
default=task_class.email_config or {}, default=task_class.email_config or {},
sample_default={ sample_default={
"initial": None, "initial": None,
"token": {"subject": "Some custom subject",}, "token": {
"subject": "Some custom subject",
},
}, },
) )
) )
@ -424,8 +426,7 @@ class BaseTask(object):
create_notification(self.task, notes) create_notification(self.task, notes)
def approve(self, approved_by="system"): 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) self.confirm_state(completed=False, cancelled=False)

View File

@ -122,7 +122,11 @@ def send_stage_email(task, email_conf, token=None):
} }
email = EmailMultiAlternatives( 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: if html_template:

View File

@ -15,5 +15,6 @@
from setuptools import setup from setuptools import setup
setup( setup(
setup_requires=["pbr"], pbr=True, setup_requires=["pbr"],
pbr=True,
) )