Exemplo n.º 1
0
    def _config_cmd(self, pav_cfg, args):
        """Show the whole pavilion config or a config template."""

        if args.template:
            config.PavilionConfigLoader().dump(self.outfile)
        else:
            config.PavilionConfigLoader().dump(self.outfile, values=pav_cfg)
Exemplo n.º 2
0
    def _config_cmd(pav_cfg, args, outfile=sys.stdout):

        if args.template:
            config.PavilionConfigLoader().dump(sys.stdout)
        else:
            config.PavilionConfigLoader().dump(outfile,
                                               values=pav_cfg)
Exemplo n.º 3
0
    def test_get(self):

        # Try to get a configuration from the testing pavilion.yaml file.
        try:
            pav_cfg = config.PavilionConfigLoader().load(open(self.PAV_CONFIG_PATH))
        except FileNotFoundError:
            self._logger.error("Could not find pavilion config at '{}'. You'll probably need to "
                               "setup the proxy information for this test."
                               .format(self.PAV_CONFIG_PATH))
            pav_cfg = config.PavilionConfigLoader().load_empty()

        info = wget.head(pav_cfg, self.GET_TARGET)

        # Make sure we can pull basic info using an HTTP HEAD.
        # The Etag can change pretty easily; and the content-encoding may muck with the length,
        # so we can't really verify these.
        self.assertIn('Content-Length', info)
        self.assertIn('ETag', info)

        # Note that there are race conditions with this, however, it is unlikely they will ever be
        # encountered in this context.
        dest_fn = tempfile.mktemp(dir='/tmp')

        # Raises an exception on failure.
        wget.get(pav_cfg, self.GET_TARGET, dest_fn)

        self.assertEqual(get_hash(self.LOCAL_TARGET), get_hash(dest_fn))

        os.unlink(dest_fn)
Exemplo n.º 4
0
    def __init__(self, *args, **kwargs):
        """Setup the pav_cfg object, and do other initialization required by
        pavilion."""

        # Open the default pav config file (found in
        # test/data/pav_config_dir/pavilion.yaml), modify it, and then
        # save the modified file to a temp location and read it instead.
        with self.PAV_CONFIG_PATH.open() as cfg_file:
            raw_pav_cfg = config.PavilionConfigLoader().load(cfg_file)

        raw_pav_cfg.config_dirs = [self.TEST_DATA_ROOT/'pav_config_dir',
                                   self.PAV_LIB_DIR]

        raw_pav_cfg.working_dir = self.PAV_ROOT_DIR/'test'/'working_dir'
        raw_pav_cfg.user_config = False

        raw_pav_cfg.result_log = raw_pav_cfg.working_dir/'results.log'

        if not raw_pav_cfg.working_dir.exists():
            raw_pav_cfg.working_dir.mkdir()

        cfg_dir = raw_pav_cfg.working_dir/'pav_cfgs'
        if not cfg_dir.exists():
            cfg_dir.mkdir()

        cfg_path = Path(tempfile.mktemp(
            suffix='.yaml',
            dir=str(cfg_dir)))

        with cfg_path.open('w') as pav_cfg_file:
            config.PavilionConfigLoader().dump(pav_cfg_file,
                                               raw_pav_cfg)

        with cfg_path.open() as cfg_file:
            self.pav_cfg = config.PavilionConfigLoader().load(cfg_file)

        self.pav_cfg.pav_cfg_file = cfg_path

        self.pav_cfg.pav_vars = pavilion_variables.PavVars()

        if not self.pav_cfg.working_dir.exists():
            self.pav_cfg.working_dir.mkdir(parents=True)

        # Create the basic directories in the working directory
        for path in self.WORKING_DIRS:
            path = self.pav_cfg.working_dir/path
            if not path.exists():
                path.mkdir()

        self.tmp_dir = tempfile.TemporaryDirectory()

        # We have to get this to set up the base argument parser before
        # plugins can add to it.
        _ = arguments.get_parser()
        super().__init__(*args, **kwargs)
Exemplo n.º 5
0
    def __init__(self, *args, **kwargs):

        super().__init__(*args, **kwargs)

        # Do a default pav config, which will load from
        # the pavilion lib path.
        self.pav_config = config.PavilionConfigLoader().load_empty()
Exemplo n.º 6
0
    def test_module_wrappers(self):
        """Make sure module wrapper loading is sane too."""

        # Get an empty pavilion config and set some config dirs on it.
        pav_cfg = config.PavilionConfigLoader().load_empty()

        # We're loading multiple directories of plugins - AT THE SAME TIME!
        pav_cfg.config_dirs = [
            os.path.join(self.TEST_DATA_ROOT, 'pav_config_dir'),
            os.path.join(self.TEST_DATA_ROOT, 'pav_config_dir2')
        ]

        plugins.initialize_plugins(pav_cfg)

        module_wrapper.get_module_wrapper('foo', '1.0')
        bar1 = module_wrapper.get_module_wrapper('bar', '1.3')
        bar2 = module_wrapper.get_module_wrapper('bar', '1.2.0')
        self.assertIsNot(bar1, bar2)

        self.assertEqual('1.3', bar1.get_version('1.3'))
        self.assertEqual('1.2.0', bar2.get_version('1.2.0'))
        self.assertRaises(module_wrapper.ModuleWrapperError,
                          lambda: bar2.get_version('1.3.0'))

        bar1.load({})

        plugins._reset_plugins()
Exemplo n.º 7
0
    def test_command_plugins(self):
        """Make sure command plugin loading is sane."""

        # Get an empty pavilion config and set some config dirs on it.
        pav_cfg = config.PavilionConfigLoader().load_empty()

        # We're loading multiple directories of plugins - AT THE SAME TIME!
        pav_cfg.config_dirs = [
            os.path.join(self.TEST_DATA_ROOT, 'pav_config_dir'),
            os.path.join(self.TEST_DATA_ROOT, 'pav_config_dir2')
        ]

        plugins.initialize_plugins(pav_cfg)

        commands.get_command('poof').run(pav_cfg, [])
        commands.get_command('blarg').run(pav_cfg, [])

        # Clean up our plugin initializations.
        plugins._reset_plugins()

        pav_cfg.config_dirs.append(
            os.path.join(self.TEST_DATA_ROOT, 'pav_config_dir_conflicts'))

        self.assertRaises(plugins.PluginError,
                          lambda: plugins.initialize_plugins(pav_cfg))

        # Clean up our plugin initializations.
        plugins._reset_plugins()
Exemplo n.º 8
0
    def test_plugin_loading(self):
        """Check to make sure the plugin system initializes correctly. Separate
        tests will check the internal initialization of each plugin
        sub-system."""

        # Get an empty pavilion config and set some config dirs on it.
        pav_cfg = config.PavilionConfigLoader().load_empty()

        # We're loading multiple directories of plugins - AT THE SAME TIME!
        pav_cfg.config_dirs = [
            os.path.join(self.TEST_DATA_ROOT, 'pav_config_dir'),
            os.path.join(self.TEST_DATA_ROOT, 'pav_config_dir2')
        ]

        for path in pav_cfg.config_dirs:
            self.assertTrue(os.path.exists(path))

        plugins.initialize_plugins(pav_cfg)

        created_manager = plugins._PLUGIN_MANAGER

        # Make sure this can run multiple times,
        plugins.initialize_plugins(pav_cfg)

        # Make sure only one of these is ever created.
        self.assertIs(created_manager, plugins._PLUGIN_MANAGER)

        # Clean up our plugin initializations.
        plugins._reset_plugins()
Exemplo n.º 9
0
    def __init__(self, *args, **kwargs):

        with open(self.PAV_CONFIG_PATH) as cfg_file:
            self.pav_cfg = config.PavilionConfigLoader().load(cfg_file)

        self.pav_cfg.config_dirs = [
            os.path.join(self.TEST_DATA_ROOT, 'pav_config_dir')
        ]

        self.tmp_dir = tempfile.TemporaryDirectory()

        #self.pav_cfg.working_dir = self.tmp_dir.name
        self.pav_cfg.working_dir = '/tmp/{}/pav_tests/'.format(os.getlogin())

        # Create the basic directories in the working directory
        for path in [
                self.pav_cfg.working_dir,
                os.path.join(self.pav_cfg.working_dir, 'builds'),
                os.path.join(self.pav_cfg.working_dir, 'tests'),
                os.path.join(self.pav_cfg.working_dir, 'suites'),
                os.path.join(self.pav_cfg.working_dir, 'downloads')
        ]:
            if not os.path.exists(path):
                os.makedirs(path, exist_ok=True)

        super().__init__(*args, **kwargs)
Exemplo n.º 10
0
    def __init__(self, *args, **kwargs):

        with self.PAV_CONFIG_PATH.open() as cfg_file:
            raw_pav_cfg = config.PavilionConfigLoader().load(cfg_file)

        raw_pav_cfg.config_dirs = [
            self.TEST_DATA_ROOT / 'pav_config_dir', self.PAV_LIB_DIR
        ]

        raw_pav_cfg.working_dir = Path('/tmp') / get_login() / 'pav_tests'

        raw_pav_cfg.result_log = raw_pav_cfg.working_dir / 'results.log'

        if not raw_pav_cfg.working_dir.exists():
            raw_pav_cfg.working_dir.mkdir()

        cfg_dir = raw_pav_cfg.working_dir / 'pav_cfgs'
        if not cfg_dir.exists():
            cfg_dir.mkdir()

        cfg_path = Path(tempfile.mktemp(suffix='.yaml', dir=str(cfg_dir)))

        with cfg_path.open('w') as pav_cfg_file:
            config.PavilionConfigLoader().dump(pav_cfg_file, raw_pav_cfg)

        with cfg_path.open() as cfg_file:
            self.pav_cfg = config.PavilionConfigLoader().load(cfg_file)

        self.pav_cfg.pav_cfg_file = cfg_path

        # Create the basic directories in the working directory
        for path in [
                self.pav_cfg.working_dir, self.pav_cfg.working_dir / 'builds',
                self.pav_cfg.working_dir / 'tests',
                self.pav_cfg.working_dir / 'series',
                self.pav_cfg.working_dir / 'users',
                self.pav_cfg.working_dir / 'downloads'
        ]:
            if not path.exists():
                os.makedirs(str(path), exist_ok=True)

        self.tmp_dir = tempfile.TemporaryDirectory()

        # We have to get this to set up the base argument parser before
        # plugins can add to it.
        _ = arguments.get_parser()
        super().__init__(*args, **kwargs)
Exemplo n.º 11
0
    def __init__(self, *args, **kwargs):

        super().__init__(*args, **kwargs)

        # Do a default pav config, which will load from
        # the pavilion lib path.
        self.pav_config = config.PavilionConfigLoader().load_empty()
        self.pav_config.config_dirs = [self.TEST_DATA_ROOT / 'pav_config_dir']
Exemplo n.º 12
0
    def test_blank_cycle(self):
        """Ensure we can both write and read the config template."""

        loader = config.PavilionConfigLoader()

        file = io.StringIO()

        loader.dump(file)
        file.seek(0)
        loader.load(file)
Exemplo n.º 13
0
    def test_update(self):

        # Try to get a configuration from the testing pavilion.yaml file.
        try:
            pav_cfg = config.PavilionConfigLoader().load(open(self.PAV_CONFIG_PATH))
        except FileNotFoundError:
            self._logger.error("Could not find pavilion config at '{}'. You'll probably need to "
                               "setup the proxy information for this test."
                               .format(self.PAV_CONFIG_PATH))
            pav_cfg = config.PavilionConfigLoader().load_empty()

        dest_fn = tempfile.mktemp(dir='/tmp')
        info_fn = '{}.info'.format(dest_fn)

        self.assertFalse(os.path.exists(dest_fn))
        self.assertFalse(os.path.exists(info_fn))

        # Update should get the file if it doesn't exist.
        wget.update(pav_cfg, self.GET_TARGET, dest_fn)
        self.assertTrue(os.path.exists(dest_fn))
        self.assertTrue(os.path.exists(info_fn))

        # It should update the file if the info file isn't there and the sizes don't match.
        ctime = os.stat(dest_fn).st_ctime
        with open(dest_fn, 'ab') as dest_file:
            dest_file.write(b'a')
        os.unlink(info_fn)
        wget.update(pav_cfg, self.GET_TARGET, dest_fn)
        new_ctime = os.stat(dest_fn).st_ctime
        self.assertNotEqual(new_ctime, ctime)
        ctime = new_ctime

        # We'll muck up the info file data, to force an update.
        with dbm.open(info_fn, 'w') as db:
            db['ETag'] = 'nope'
            db['Content-Length'] = '-1'
        wget.update(pav_cfg, self.GET_TARGET, dest_fn)
        new_ctime = os.stat(dest_fn).st_ctime
        self.assertNotEqual(new_ctime, ctime)

        os.unlink(dest_fn)
        os.unlink(info_fn)
Exemplo n.º 14
0
    def test_cycle(self):
        """Make sure we can load the defaults, save them, and reload them."""

        loader = config.PavilionConfigLoader()

        pav_cfg = loader.load_empty()

        file = io.StringIO()

        loader.dump(file, pav_cfg)

        file.seek(0)

        new_cfg = loader.load(file)

        self.assertEqual(pav_cfg, new_cfg)
Exemplo n.º 15
0
    def test_result_parser_plugins(self):
        """Check basic result parser structure."""

        # Get an empty pavilion config and set some config dirs on it.
        pav_cfg = config.PavilionConfigLoader().load_empty()

        plugins.initialize_plugins(pav_cfg)

        # We're loading multiple directories of plugins - AT THE SAME TIME!
        pav_cfg.config_dirs = [
            os.path.join(self.TEST_DATA_ROOT, 'pav_config_dir')
        ]

        # We should have exactly one test plugin.
        self.assertEqual(len(result_parsers.list_plugins()), 1)

        regex = result_parsers.get_plugin('regex')

        plugins._reset_plugins()
Exemplo n.º 16
0
    def test_system_plugins(self):
        """Make sure system values appear as expected.  Also that deferred
        variables behave as expected."""

        # Get an empty pavilion config and set some config dirs on it.
        pav_cfg = config.PavilionConfigLoader().load_empty()

        plugins.initialize_plugins(pav_cfg)

        self.assertFalse(system_variables._LOADED_PLUGINS is None)

        host_arch = subprocess.check_output(['uname', '-i'])
        host_arch = host_arch.strip().decode('UTF-8')

        host_name = subprocess.check_output(['hostname', '-s'])
        host_name = host_name.strip().decode('UTF-8')

        with open('/etc/os-release', 'r') as release:
            rlines = release.readlines()

        host_os = {}
        for line in rlines:
            if line[:3] == 'ID=':
                host_os['ID'] = line[3:].strip().strip('"')
            elif line[:11] == 'VERSION_ID=':
                host_os['Version'] = line[11:].strip().strip('"')

        sys_vars = system_variables.get_system_plugin_dict(defer=False)

        self.assertFalse('sys_arch' in sys_vars)
        self.assertEqual(host_arch, sys_vars['sys_arch'])
        self.assertTrue('sys_arch' in sys_vars)

        self.assertFalse('sys_name' in sys_vars)
        self.assertEqual(host_name, sys_vars['sys_name'])
        self.assertTrue('sys_name' in sys_vars)

        self.assertFalse('sys_os' in sys_vars)
        self.assertEqual(host_os['ID'], sys_vars['sys_os']['ID'])
        self.assertEqual(host_os['Version'], sys_vars['sys_os']['Version'])
        self.assertTrue('sys_os' in sys_vars)

        self.assertFalse('host_arch' in sys_vars)
        self.assertEqual(host_arch, sys_vars['host_arch'])
        self.assertTrue('host_arch' in sys_vars)

        self.assertFalse('host_name' in sys_vars)
        self.assertEqual(host_name, sys_vars['host_name'])
        self.assertTrue('host_name' in sys_vars)

        self.assertFalse('host_os' in sys_vars)
        self.assertEqual(host_os['ID'], sys_vars['host_os']['ID'])
        self.assertEqual(host_os['Version'], sys_vars['host_os']['Version'])
        self.assertTrue('host_os' in sys_vars)

        # Re-initialize the plugin system.
        plugins._reset_plugins()
        # Make sure these have been wiped
        self.assertIsNone(system_variables._LOADED_PLUGINS)
        # Make sure these have been wiped.
        self.assertIsNone(system_variables._SYS_VAR_DICT)

        plugins.initialize_plugins(pav_cfg)

        # but these are back
        self.assertIsNotNone(system_variables._LOADED_PLUGINS)

        sys_vars = system_variables.get_system_plugin_dict(defer=True)

        self.assertTrue(len(system_variables._SYS_VAR_DICT.items()) == 0)

        # Check that the deferred values are actually deferred.
        self.assertFalse('host_arch' in sys_vars)
        self.assertTrue(
            isinstance(sys_vars['host_arch'], variables.DeferredVariable))
        self.assertFalse('host_name' in sys_vars)
        self.assertTrue(
            isinstance(sys_vars['host_name'], variables.DeferredVariable))
        self.assertFalse('host_os' in sys_vars)
        self.assertTrue(
            isinstance(sys_vars['host_os'], variables.DeferredVariable))

        plugins._reset_plugins()
Exemplo n.º 17
0
    def _config_cmd(self, pav_cfg, args):

        if args.template:
            config.PavilionConfigLoader().dump(self.outfile)
        else:
            config.PavilionConfigLoader().dump(self.outfile, values=pav_cfg)