def main():
    expected_annotations = []
    test_result_files = glob.glob("tests/test_annotation_host*")
    for file in test_result_files:
        with open(file) as json_file:
            data = json.load(json_file)
            expected_annotations.append(data)

    with open("installer_dir/bootstrap.ign", "r") as file_obj:
        data = json.load(file_obj)
        storage_files = data['storage']['files']
        for file_data in storage_files:
            if bmh_utils.is_bmh_cr_file(file_data['path']):
                bmh_dict = bmh_utils.get_bmh_dict_from_file(file_data)
                annotations = bmh_dict['metadata']['annotations']
                res_annotation = json.loads(
                    annotations['baremetalhost.metal3.io/status'])
                found = False
                for annot in expected_annotations[:]:
                    if annot == res_annotation:
                        expected_annotations.remove(annot)
                        found = True
                if not found:
                    raise Exception("no matching expected annotation for: ",
                                    json.dumps(res_annotation))
        if len(expected_annotations) != 0:
            raise Exception("some expected annotations were not found")
    print("BMH Test finished successfully")
Пример #2
0
def update_bmh_files(ignition_file, cluster_id, inventory_endpoint, token):
    try:
        if inventory_endpoint:
            hosts_list = utils.get_inventory_hosts(inventory_endpoint,
                                                   cluster_id, token)
        else:
            logging.info("Using test data to get hosts list")
            hosts_list = test_utils.get_test_list_hosts(cluster_id)

        with open(ignition_file, "r") as file_obj:
            data = json.load(file_obj)
            storage_files = data['storage']['files']
            # since we don't remove file for now, we don't need to iterate through copy
            # for file_data in storage_files[:]:
            for file_data in storage_files:
                # if file_data['path'] == '/etc/motd':
                #    storage_files.remove(file_data)
                if bmh_utils.is_bmh_cr_file(file_data['path']):
                    bmh_utils.update_bmh_cr_file(file_data, hosts_list)

        with open(ignition_file, "w") as file_obj:
            json.dump(data, file_obj)
    except Exception as ex:
        raise Exception(
            'Failed to update BMH CRs in bootstrap ignition, exception: {}'.
            format(ex))
def update_bmh_files(ignition_file, cluster_id, inventory_endpoint, token,
                     skip_cert_verification=False, ca_cert_path=None):
    try:
        if inventory_endpoint:
            hosts_list = utils.get_inventory_hosts(inventory_endpoint, cluster_id, token,
                                                   skip_cert_verification, ca_cert_path)
        else:
            logging.info("Using test data to get hosts list")
            hosts_list = test_utils.get_test_list_hosts(cluster_id)

        with open(ignition_file, "r") as file_obj:
            data = json.load(file_obj)
            storage_files = data['storage']['files']
            for file_data in storage_files[:]:
                if file_data['path'] == '/etc/motd' or 'baremetal-provisioning-config' in file_data['path']:
                    storage_files.remove(file_data)
                if bmh_utils.is_bmh_cr_file(file_data['path']):
                    bmh_utils.update_bmh_cr_file(file_data, hosts_list)

        with open(ignition_file, "w") as file_obj:
            json.dump(data, file_obj)
    except Exception as ex:
        raise Exception('Failed to update BMH CRs in bootstrap ignition, exception: {}'.format(ex))