disabled
  #   ˆl–Ãa¾”je¶¥@·pA¸&ÔÅ£¿„„ÓßÂÁ ?÷     # Copyright (C) 2017 Red Hat, Inc., Bryn M. Reeves <bmr@redhat.com>
#
# osprofile_tests.py - Boom OS profile tests.
#
# This file is part of the boom project.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions
# of the GNU General Public License v.2.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import unittest
import logging
from sys import stdout
from os import listdir, makedirs
from os.path import abspath, exists, join
import shutil

log = logging.getLogger()
log.level = logging.DEBUG
log.addHandler(logging.FileHandler("test.log"))

from boom.osprofile import *
from boom.hostprofile import *
from boom.bootloader import *
from boom import *

# For private member validation checks
import boom.hostprofile

from tests import *

BOOT_ROOT_TEST = abspath("./tests")
set_boot_path(BOOT_ROOT_TEST)

BOOM_ENTRY_MACHINE_ID="BOOM_ENTRY_MACHINE_ID"

def _count_value_in_key(dir_path, ext, key_name, xvalue,
                        exact=False, default=False):
    """Helper function to count the number of times ``xvalue`` appears
        as the value of key ``key_name`` in the set of files found in
        ``dir_path`` having file extension ``ext`.

        If ``exact`` is true the value is compared for equality.
        Otherwise the value is counted if the string ``value`` appears
        anywhere within the named key value.

        If ``default`` is ``True``, and the key is not found in a
        profile, it is assumed that ``xvalue`` is the default value,
        and that the relevant profile has inherited this value from
        the embedded ``OsProfile`` defaults.

        This is used to count profiles by property independently of
        the ``boom`` library modules for comparison of results
        returned from the API.
    """
    count = 0
    filecount = 1
    for f_name in listdir(dir_path):
        if not f_name.endswith(ext):
            continue
        f_path = join(dir_path, f_name)
        found_in_file = False
        with open(f_path, "r") as f:
            for line in f.readlines():
                (key, value) = parse_name_value(line)
                if key not in HOST_PROFILE_KEYS:
                    continue
                if key == key_name:
                    found_in_file = True
                    if not exact:
                        count += 1 if xvalue in value else 0
                    else:
                        count += 1 if xvalue == value else 0
            if default and not found_in_file:
                count += 1
            filecount += 1
    return count


class HostProfileTests(unittest.TestCase):
    # Master boom configuration path for sandbox
    boom_path = join(BOOT_ROOT_TEST, "boom")

    # Master BLS loader directory for sandbox
    loader_path = join(BOOT_ROOT_TEST, "loader")

    def setUp(self):
        reset_sandbox()

        # Sandbox paths
        boot_sandbox = join(SANDBOX_PATH, "boot")
        boom_sandbox = join(SANDBOX_PATH, "boot/boom")
        loader_sandbox = join(SANDBOX_PATH, "boot/loader")

        makedirs(boot_sandbox)
        shutil.copytree(self.boom_path, boom_sandbox)
        shutil.copytree(self.loader_path, loader_sandbox)

        set_boot_path(boot_sandbox)

        drop_host_profiles()
        drop_profiles()

    def tearDown(self):
        drop_host_profiles()
        drop_profiles()
        rm_sandbox()
        reset_boom_paths()

    # Module tests
    def test_import(self):
        import boom.hostprofile

    # Profile store tests

    def test_load_profiles(self):
        # Test that loading the test profiles succeeds.
        load_host_profiles()

    # HostProfile tests

    def test_HostProfile__str__(self):
        load_profiles()
        load_host_profiles()
        hp = HostProfile(machine_id="ffffffffffffffff", h