Skip to content

Commit

Permalink
#2974 and #2976 (#2977)
Browse files Browse the repository at this point in the history
- Refactored Apply command #2974
- Added option for custom terraform scripts by the user #2976
- Moved Azure specific code from TerraformRunner to APIProxy
- Seperated filetype into schema and  template types.
- Fixed tests and sorted tests imports.
  • Loading branch information
seriva authored Feb 24, 2022
1 parent f058984 commit d58ceab
Show file tree
Hide file tree
Showing 38 changed files with 377 additions and 290 deletions.
5 changes: 2 additions & 3 deletions cli/src/ansible/AnsibleInventoryUpgrade.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from cli.src.helpers.build_io import (get_inventory_path_for_build,
load_inventory, load_manifest,
save_inventory)
from cli.src.helpers.data_loader import load_schema_obj
from cli.src.helpers.data_loader import types as data_types
from cli.src.helpers.data_loader import load_schema_obj, schema_types
from cli.src.helpers.doc_list_helpers import select_single
from cli.src.helpers.objdict_helpers import merge_objdict
from cli.src.models.AnsibleHostModel import AnsibleHostModel
Expand Down Expand Up @@ -73,7 +72,7 @@ def upgrade(self):
self.cluster_model = select_single(self.manifest_docs, lambda x: x.kind == 'epiphany-cluster')

# Merge manifest cluster config with newer defaults
default_cluster_model = load_schema_obj(data_types.DEFAULT, self.cluster_model.provider, 'epiphany-cluster')
default_cluster_model = load_schema_obj(schema_types.DEFAULT, self.cluster_model.provider, 'epiphany-cluster')
merge_objdict(default_cluster_model, self.cluster_model)
self.cluster_model = default_cluster_model

Expand Down
6 changes: 2 additions & 4 deletions cli/src/ansible/AnsibleRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
get_ansible_path_for_build,
get_inventory_path,
get_inventory_path_for_build)
from cli.src.helpers.data_loader import BASE_DIR, types
from cli.src.helpers.data_loader import ANSIBLE_PLAYBOOK_PATH
from cli.src.helpers.naming_helpers import to_role_name
from cli.src.Step import Step


class AnsibleRunner(Step):
ANSIBLE_PLAYBOOKS_PATH = os.path.join(BASE_DIR, types.ANSIBLE, 'playbooks')

def __init__(self, cluster_model=None, config_docs=None, build_dir=None, backup_build_dir=None,
ansible_options=None, ping_retries: int = 5):
super().__init__(__name__)
Expand Down Expand Up @@ -54,7 +52,7 @@ def copy_resources(self):
ansible_dir = get_ansible_path_for_build(self.build_dir)

delete_directory(ansible_dir)
copy_files_recursively(AnsibleRunner.ANSIBLE_PLAYBOOKS_PATH, ansible_dir)
copy_files_recursively(ANSIBLE_PLAYBOOK_PATH, ansible_dir)

def pre_flight(self, inventory_path):
self.logger.info('Checking connection to each machine')
Expand Down
7 changes: 3 additions & 4 deletions cli/src/ansible/AnsibleVarsGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
get_ansible_path_for_build,
get_ansible_vault_path)
from cli.src.helpers.data_loader import (load_all_schema_objs_from_directory,
load_schema_obj, types)
load_schema_obj, schema_types)
from cli.src.helpers.doc_list_helpers import (ExpectedSingleResultException,
select_first, select_single)
from cli.src.helpers.naming_helpers import to_feature_name, to_role_name
Expand All @@ -33,7 +33,7 @@ def __init__(self, inventory_creator=None, inventory_upgrade=None):
elif inventory_upgrade is not None and inventory_creator is None:
self.cluster_model = inventory_upgrade.cluster_model
self.config_docs = []
defaults = load_all_schema_objs_from_directory(types.DEFAULT, 'common', 'configuration')
defaults = load_all_schema_objs_from_directory(schema_types.DEFAULT, 'common', 'configuration')
for default in defaults:
config_doc = select_first(inventory_upgrade.config_docs, lambda x: x.kind == default.kind)
if config_doc is None:
Expand Down Expand Up @@ -90,7 +90,6 @@ def generate(self):

document = select_first(self.config_docs, lambda x: x.kind == kind)
if document is None:
self.logger.warn('No config document for enabled role: ' + role)
continue
document.specification['provider'] = self.cluster_model.provider

Expand Down Expand Up @@ -164,7 +163,7 @@ def populate_group_vars(self, ansible_dir):

# Fallback if there is completely no trace of the shared-config doc
if shared_config_doc is None:
shared_config_doc = load_schema_obj(types.DEFAULT, 'common', 'configuration/shared-config')
shared_config_doc = load_schema_obj(schema_types.DEFAULT, 'common', 'configuration/shared-config')

self.set_vault_path(shared_config_doc)
main_vars.update(shared_config_doc.specification)
Expand Down
Loading

0 comments on commit d58ceab

Please sign in to comment.