Пример #1
0
def slate_deploy():

    module_root = get_module_root()
    print(f"Module root: {module_root}")

    conf_path = f'{module_root}conf'
    print(f"conf_path: {conf_path}")

    plan_path = f'{module_root}plan'
    print(f"plan_path: {plan_path}")

    env = 'docker'
    apply_kube = True
    plan_format = 'yaml'

    vars_conf_path = f'{conf_path}/{env}/slate-vars.conf'
    storage_conf_path = f'{conf_path}/{env}/slate-storage.conf'
    pv_conf_path = f'{conf_path}/slate-pv.conf'
    pvc_conf_path = f'{conf_path}/slate-pvc.conf'
    deploy_file_path = f'{conf_path}/slate-deploy.conf'

    confs = [
        vars_conf_path, storage_conf_path, pv_conf_path, pvc_conf_path,
        deploy_file_path
    ]

    included = wrap_included(confs)

    print(f'\nincluded: {included}')

    conf = Cf.parse_string(included)

    storage_plan = HOCONConverter.convert(conf.storage, plan_format, 2)
    pv_plan = HOCONConverter.convert(conf.pv, plan_format, 2)
    pvc_plan = HOCONConverter.convert(conf.pvc, plan_format, 2)
    deploy_plan = HOCONConverter.convert(conf.deploy, plan_format, 2)

    print(f'\n{storage_plan}')
    print(f'\n{pv_plan}')
    print(f'\n{pvc_plan}')
    print(f'\n{deploy_plan}')

    plans1 = [(f'{plan_path}/slate-storage.{plan_format}', storage_plan),
              (f'{plan_path}/slate-pv.{plan_format}', pv_plan),
              (f'{plan_path}/slate-pvc.{plan_format}', pvc_plan),
              (f'{plan_path}/slate-deploy.{plan_format}', deploy_plan)]

    plan(plans1)

    for pl in plans1:

        os.system(f"kubectl apply -f {pl[0]};")

    # Observe the pods created
    init_observe_pods(deploy_tuple=('slate',
                                    f'{plan_path}/slate-deploy.{plan_format}'),
                      use_minikube_repo=False,
                      callback=slate_deploy_init_callback,
                      init=False)
Пример #2
0
 def _test_convert_from_file(self, input, expected_output, format):
     with tempfile.NamedTemporaryFile('w') as fdin:
         fdin.write(input)
         fdin.flush()
         with tempfile.NamedTemporaryFile('r') as fdout:
             HOCONConverter.convert_from_file(fdin.name, fdout.name, format)
             with open(fdout.name) as fdi:
                 converted = fdi.read()
                 assert [line.strip() for line in expected_output.split('\n') if line.strip()]\
                     == [line.strip() for line in converted.split('\n') if line.strip()]
Пример #3
0
 def _test_convert(self, input, expected_output, format):
     with tempfile.NamedTemporaryFile('w') as fdin:
         fdin.write(input)
         fdin.flush()
         with tempfile.NamedTemporaryFile('r') as fdout:
             HOCONConverter.convert(fdin.name, fdout.name, format)
             with open(fdout.name) as fdi:
                 converted = fdi.read()
                 assert [line.strip() for line in expected_output.split('\n') if line.strip()]\
                     == [line.strip() for line in converted.split('\n') if line.strip()]
Пример #4
0
 def run(self, df):
     #return df.agg(['mean', 'min', 'max'])
     rConfigTree = ConfigFactory.parse_file(
         'defaultLeaderboardResponse.conf').get("LeaderboardComprehensive")
     r = HOCONConverter.convert(rConfigTree, 'json')
     print(r)
     return r
Пример #5
0
 def test_config_tree_special_characters(self):
     special_characters = '$}[]:=+#`^?!@*&.'
     for char in special_characters:
         config_tree = ConfigTree()
         escaped_key = "\"test{char}key\"".format(char=char)
         key = "a.b.{escaped_key}".format(escaped_key=escaped_key)
         config_tree.put(key, "value")
         hocon_tree = HOCONConverter.to_hocon(config_tree)
         assert escaped_key in hocon_tree
         parsed_tree = ConfigFactory.parse_string(hocon_tree)
         assert parsed_tree.get(key) == "value"
Пример #6
0
 def test_config_tree_special_characters(self):
     special_characters = '$}[]:=+#`^?!@*&.'
     for char in special_characters:
         config_tree = ConfigTree()
         escaped_key = "\"test{char}key\"".format(char=char)
         key = "a.b.{escaped_key}".format(escaped_key=escaped_key)
         config_tree.put(key, "value")
         hocon_tree = HOCONConverter.to_hocon(config_tree)
         assert escaped_key in hocon_tree
         parsed_tree = ConfigFactory.parse_string(hocon_tree)
         assert parsed_tree.get(key) == "value"
Пример #7
0
def load_config(config_path: str) -> InfraGraphConfig:
    system_config_path = SYSTEM_CONFIG_ROOT / "config.hocon"
    config = Path(config_path)
    if config.exists():
        logger.info("Using local config")
        config_to_load = config
    elif system_config_path.exists():
        config_to_load = system_config_path
    else:
        logger.error(
            f"No config found to load. Run the `init` command or have a local config '{config_path} available'"
        )
        sys.exit(1)

    hocon_conf = ConfigFactory.parse_file(config_to_load)
    config_dict = json.loads(
        HOCONConverter.to_json(hocon_conf.get("infraGraph")))
    return InfraGraphConfig(**config_dict)
Пример #8
0
    def plan(self):

        for res in self.ordered_kube_resources:

            plan = Hc.convert(self.conf[res], self.plan_format.value, 2)

            logging.info(f'\n{plan}')

            self.plans.append(plan)

            if not os.path.exists(self.plan_dir):
                os.makedirs(self.plan_dir)

            plan_path = self.to_plan_path(res=res)

            with open(plan_path, 'wt') as file_out:
                file_out.write(plan)

            self.plan_paths.append(plan_path)
Пример #9
0
 def test_to_hocon(self):
     converted = HOCONConverter.to_hocon(TestHOCONConverter.CONFIG)
     assert [line.strip() for line in TestHOCONConverter.EXPECTED_HOCON.split('\n') if line.strip()]\
         == [line.strip() for line in converted.split('\n') if line.strip()]
Пример #10
0
 def test_to_properties(self):
     converted = HOCONConverter.to_properties(TestHOCONConverter.CONFIG)
     assert [line.strip() for line in TestHOCONConverter.EXPECTED_PROPERTIES.split('\n') if line.strip()]\
         == [line.strip() for line in converted.split('\n') if line.strip()]
Пример #11
0
 def test_to_properties(self):
     converted = HOCONConverter.to_properties(TestHOCONConverter.CONFIG)
     assert [line.strip() for line in TestHOCONConverter.EXPECTED_PROPERTIES.split('\n') if line.strip()]\
         == [line.strip() for line in converted.split('\n') if line.strip()]
Пример #12
0
 def test_to_yaml(self):
     converted = HOCONConverter.to_yaml(TestHOCONConverter.CONFIG)
     assert [line.strip() for line in TestHOCONConverter.EXPECTED_YAML.split('\n') if line.strip()]\
         == [line.strip() for line in converted.split('\n') if line.strip()]
Пример #13
0
def json_string_config(conf):
    lines = HOCONConverter.convert(conf, indent=1)
    return ' '.join(lines)
Пример #14
0
def dump_config(conf, filename, output_format='hocon'):
    lines = HOCONConverter.convert(conf, output_format, indent=4)
    with open(filename, 'w') as fh:
        fh.writelines(lines)
Пример #15
0
 def test_to_compact_hocon(self):
     converted = HOCONConverter.to_hocon(TestHOCONConverter.CONFIG,
                                         compact=True)
     assert [line.strip() for line in TestHOCONConverter.EXPECTED_COMPACT_HOCON.split('\n') if line.strip()]\
         == [line.strip() for line in converted.split('\n') if line.strip()]