From 4423ee985ecf514a5c3bf73524cff11ec5222dbe Mon Sep 17 00:00:00 2001 From: Scott Hussey Date: Fri, 13 Jul 2018 09:19:53 -0500 Subject: [PATCH] Add additional repo options - Some repos are built without components that MAAS assumes are there. This allows the configuration to describe that so MAAS can be updated to disregard those components Change-Id: I4eafe9fb8278b944bcb993f10379966a01e94bf6 --- .../drivers/node/maasdriver/actions/node.py | 20 ++++++++++++++++++- .../node/maasdriver/models/repository.py | 4 ++-- drydock_provisioner/objects/site.py | 18 +++++++++++++++++ drydock_provisioner/schemas/region.yaml | 4 ++++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/drydock_provisioner/drivers/node/maasdriver/actions/node.py b/drydock_provisioner/drivers/node/maasdriver/actions/node.py index a638d55f..de72d8ee 100644 --- a/drydock_provisioner/drivers/node/maasdriver/actions/node.py +++ b/drydock_provisioner/drivers/node/maasdriver/actions/node.py @@ -622,6 +622,9 @@ class CreateNetworkTemplate(BaseMaasAction): class ConfigureNodeProvisioner(BaseMaasAction): """Action for configuring site-wide node provisioner options.""" + # These repo names cannot be deleted out of MAAS + # and maintain functionality + DEFAULT_REPOS = ['main_archive', 'ports_archive'] def start(self): self.task.set_status(hd_fields.TaskStatus.Running) @@ -689,6 +692,16 @@ class ConfigureNodeProvisioner(BaseMaasAction): self.task.add_status_msg( msg=msg, error=True, ctx='NA', ctx_type='NA') self.task.failure() + if repo_list.remove_unlisted: + defined_repos = [x.get_id() for x in repo_list] + to_delete = [r + for r + in current_repos + if r.name not in defined_repos] + for r in to_delete: + if r.name not in self.DEFAULT_REPOS: + r.delete() + current_repos.refresh() else: msg = ("No repositories to add, no work to do.") self.logger.debug(msg) @@ -714,7 +727,12 @@ class ConfigureNodeProvisioner(BaseMaasAction): if repo_obj.distributions: model_fields['distributions'] = ','.join(repo_obj.distributions) if repo_obj.components: - model_fields['components'] = ','.join(repo_obj.components) + if repo_obj.get_id() in ConfigureNodeProvisioner.DEFAULT_REPOS: + model_fields['disabled_components'] = ','.join(repo_obj.get_disabled_components()) + else: + model_fields['components'] = ','.join(repo_obj.components) + if repo_obj.get_disabled_subrepos(): + model_fields['disabled_pockets'] = ','.join(repo_obj.get_disabled_subrepos()) if repo_obj.arches: model_fields['arches'] = ','.join(repo_obj.arches) diff --git a/drydock_provisioner/drivers/node/maasdriver/models/repository.py b/drydock_provisioner/drivers/node/maasdriver/models/repository.py index 0ea49ae9..da3d0be1 100644 --- a/drydock_provisioner/drivers/node/maasdriver/models/repository.py +++ b/drydock_provisioner/drivers/node/maasdriver/models/repository.py @@ -21,11 +21,11 @@ class Repository(model_base.ResourceBase): resource_url = 'package-repositories/{resource_id}/' fields = [ 'resource_id', 'name', 'url', 'distributions', 'components', 'arches', - 'key', 'enabled' + 'key', 'enabled', 'disabled_components', 'disabled_pockets' ] json_fields = [ 'name', 'url', 'distributions', 'components', 'arches', 'key', - 'enabled' + 'enabled', 'disabled_components', 'disabled_pockets' ] def __init__(self, api_client, **kwargs): diff --git a/drydock_provisioner/objects/site.py b/drydock_provisioner/objects/site.py index 8e8b1e0a..3186a9e7 100644 --- a/drydock_provisioner/objects/site.py +++ b/drydock_provisioner/objects/site.py @@ -101,11 +101,20 @@ class Repository(base.DrydockObject): 'repo_type': ovo_fields.StringField(), 'gpgkey': ovo_fields.StringField(nullable=True), 'distributions': ovo_fields.ListOfStringsField(nullable=True), + 'subrepos': ovo_fields.ListOfStringsField(nullable=True), 'components': ovo_fields.ListOfStringsField(nullable=True), 'arches': ovo_fields.ListOfStringsField(default=['amd64']), 'options': ovo_fields.DictOfStringsField(nullable=True) } + STANDARD_COMPONENTS = { + 'apt': {'main', 'restricted', 'universe', 'multiverse'}, + } + + STANDARD_SUBREPOS = { + 'apt': {'security', 'updates', 'backports'}, + } + def __init__(self, **kwargs): super(Repository, self).__init__(**kwargs) @@ -113,6 +122,15 @@ class Repository(base.DrydockObject): def get_id(self): return self.name + def get_disabled_components(self): + enabled = set(self.components or []) + std = self.STANDARD_COMPONENTS.get(self.repo_type, ()) + return std - enabled + + def get_disabled_subrepos(self): + enabled = set(self.subrepos or []) + std = self.STANDARD_SUBREPOS.get(self.repo_type, ()) + return std - enabled @base.DrydockObjectRegistry.register class RepositoryList(base.DrydockObjectListBase, base.DrydockObject): diff --git a/drydock_provisioner/schemas/region.yaml b/drydock_provisioner/schemas/region.yaml index 05d16a6f..50d56a19 100644 --- a/drydock_provisioner/schemas/region.yaml +++ b/drydock_provisioner/schemas/region.yaml @@ -46,6 +46,10 @@ data: type: 'array' items: type: 'string' + subrepos: + type: 'array' + items: + type: 'string' components: type: 'array' items: