コード例 #1
0
def _parser_callback(args):
    if args.instance_path and not path.isdir(args.instance_path):
        raise argparse.ArgumentTypeError(
            "Directory {} is not a valid path!".format(args.instance_path))

    if args.workers < 1:
        print("{} is not a positive number!".format(args.workers))
        return 1

    storage_old = Storage.create(args.instance_path)
    comparer = TemplateComparer()
    instance_comparer = InstanceComparer()

    if args.template:
        service_template_new = args.template.name
    else:
        print("Template file for update was not supplied.")
        return 1

    try:
        if args.inputs:
            inputs_new = yaml.safe_load(args.inputs)
        else:
            inputs_new = {}
    except YAMLError as e:
        print("Invalid inputs: {}".format(e))
        return 1

    workdir_old = get_workdir(storage_old)

    try:
        with tempfile.TemporaryDirectory() as temp_path:
            storage_new = Storage.create(temp_path)
            storage_new.write_json(inputs_new, "inputs")
            storage_new.write(service_template_new, "root_file")
            workdir_new = get_workdir(storage_new)

            instance_diff = diff_instances(storage_old, workdir_old,
                                           storage_new, workdir_new, comparer,
                                           instance_comparer, args.verbose)

            update(storage_old,
                   workdir_old,
                   storage_new,
                   workdir_new,
                   instance_comparer,
                   instance_diff,
                   args.verbose,
                   args.workers,
                   overwrite=True)

    except ParseError as e:
        print("{}: {}".format(e.loc, e))
        return 1
    except DataError as e:
        print(str(e))
        return 1

    return 0
コード例 #2
0
ファイル: test_diff.py プロジェクト: xlab-si/xopera-opera
    def test_diff_service_template(self, service_template,
                                   service_template_updated):
        _, path, storage = service_template
        _, path_updated, storage_updated = service_template_updated
        deploy_service_template(path / "service.yaml",
                                {"marker": "test-marker"}, storage, False, 1,
                                True)
        deploy_service_template(path_updated / "service.yaml",
                                {"marker": "test-marker"}, storage_updated,
                                False, 1, True)

        template_comparer = TemplateComparer()
        diff_templates(path / "service.yaml", path, {"marker": "test-marker"},
                       path_updated / "service.yaml", path_updated,
                       {"another_marker": "test-marker"}, template_comparer,
                       False)
        instance_comparer = InstanceComparer()
        diff_instances(storage, path, storage_updated, path_updated,
                       template_comparer, instance_comparer, False)
コード例 #3
0
ファイル: test_workdir.py プロジェクト: xlab-si/xopera-opera
    def test_instance_diff(self, service_template1, service_template2):
        storage_1 = service_template1[3]
        storage_2 = service_template2[3]
        comparer_template = TemplateComparer()
        comparer_instance = InstanceComparer()

        diff = diff_instances(storage_1, service_template1[2], storage_2,
                              service_template2[2], comparer_template,
                              comparer_instance, False)

        assert "hello-1" in diff.changed["nodes"].changed
        assert "hello-2" in diff.changed["nodes"].changed
        assert "hello-3" in diff.changed["nodes"].changed
        assert "hello-6" in diff.changed["nodes"].changed