Example #1
0
 def test_module_version_conflict(self):
     url = "https://github.com/containers-tools/test-module-dep"
     mod_dir = tempfile.mkdtemp()
     mm = ModuleManager(mod_dir, '/tmp')
     mm.install_module(url, 'master')
     with self.assertRaisesRegexp(Exception, 'Conflicting module.*'):
         mm.install_module(url, '1.0')
     shutil.rmtree(mod_dir)
Example #2
0
 def test_moudule_deps(self):
     url = "https://github.com/containers-tools/test-module-dep"
     version = "master"
     deps = {"dependencies": [{"url": url, "version": version}]}
     mod_dir = tempfile.mkdtemp()
     module_manager = ModuleManager(mod_dir, '/tmp')
     module_manager.process_module_deps(deps['dependencies'])
     shutil.rmtree(mod_dir)
Example #3
0
 def test_module_version_override(self):
     url = "https://github.com/containers-tools/test-module-dep"
     mod_dir = tempfile.mkdtemp()
     mm = ModuleManager(mod_dir, '/tmp')
     mm.install_module(url, '1.0', override=True)
     mm.install_module(url, 'master')
     self.assertEquals(mm.modules['test-module-dep.dummy'].version, '1.0')
     self.assertTrue(mm.modules['test-module-dep.dummy'].override)
     shutil.rmtree(mod_dir)
Example #4
0
 def test_module_script(self):
     mod_dir = os.path.join(tempfile.mkdtemp(), 'scripts')
     mm = ModuleManager(mod_dir, '/tmp')
     script = os.path.join(mod_dir, 'test', 'script')
     module = os.path.join(mod_dir, 'module.yaml')
     modconfig =  { 'language' : [ 'script']}
     os.makedirs(os.path.dirname(script))
     with open(module, 'w') as modfile:
         yaml.dump(modconfig, modfile, default_flow_style=False)
     shutil.copy(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'script'), script)
     mm.discover_modules(mod_dir)
     mod =  mm.modules['scripts.test']
     mod.script()
Example #5
0
 def test_moudule_deps(self):
     url = "https://github.com/containers-tools/test-module-dep"
     version = "master"
     deps = {
         "dependencies": [
             {
                 "url": url,
                 "version": version
             }
         ]
     }
     mod_dir = tempfile.mkdtemp()
     module_manager = ModuleManager(mod_dir, '/tmp')
     module_manager.process_module_deps(deps['dependencies'])
     shutil.rmtree(mod_dir)
Example #6
0
 def test_module_script(self):
     mod_dir = os.path.join(tempfile.mkdtemp(), 'scripts')
     mm = ModuleManager(mod_dir, '/tmp')
     script = os.path.join(mod_dir, 'test', 'script')
     module = os.path.join(mod_dir, 'module.yaml')
     modconfig = {'language': ['script']}
     os.makedirs(os.path.dirname(script))
     with open(module, 'w') as modfile:
         yaml.dump(modconfig, modfile, default_flow_style=False)
     shutil.copy(
         os.path.join(os.path.abspath(os.path.dirname(__file__)), 'script'),
         script)
     mm.discover_modules(mod_dir)
     mod = mm.modules['scripts.test']
     mod.script()
Example #7
0
File: main.py Project: jmtd/cct
 def run(self):
     self.setup_arguments()
     env_changes = None
     changes = []
     try:
         env_changes = os.environ['CCT_CHANGES']
     except KeyError:
         pass
     if len(sys.argv) < 2:
         self.parser.print_help()
         sys.exit(1)
     args = self.parser.parse_args()
     if args.get_changes:
         changes += urllib2.urlopen(args.get_changes).read().split('\n')
     if args.verbose:
         setup_logging(level=logging.DEBUG)
     elif args.quiet:
         setup_logging(level=logging.ERROR)
     else:
         setup_logging(level=logging.INFO)
     modules = ModuleManager(args.modules_dir, args.artifacts_dir)
     if args.list:
         modules.discover_modules()
         modules.list()
     elif args.show:
         modules.discover_modules()
         modules.list_module_oper(args.show)
     else:
         # env changes overrides cmdline ones
         # seems odd but really needed for containers - changes are passed
         # via docker run -e
         if env_changes:
             changes += env_changes.split()
         else:
             changes += args.changes
         try:
             self.process_changes(changes, args.modules_dir,
                                  args.artifacts_dir, args.fetch_only)
         except KeyboardInterrupt:
             pass
         except Exception:
             logger.error("CCT failed, check logs above for errors")
             exit(1)
     if args.command:
         self.exec_command(args.command)
Example #8
0
    def _process_change(self, change_cfg, fetch_only):
        logger.info("processing change %s" % change_cfg['name'])
        change_env = self._create_env_dict(change_cfg.get('environment'))
        if 'description' not in change_cfg:
            change_cfg['description'] = None
        mr = ModuleManager(self.modules_dir, self.artifacts_dir)

        if 'modules' in change_cfg:
            for module in change_cfg['modules']:
                url = module['url']
                ver = module['version'] if 'version' in module else None
                override = module['override'] if 'override' in module else False
                mr.install_module(url, ver, override)

        if fetch_only:
            artifacts = {}
            for _, module in mr.modules.items():
                for _, artifact in module.artifacts.items():
                    artifacts[artifact.filename] = artifact.hash
            return artifacts

        steps = []
        for modules in change_cfg['changes']:
            for module_name, operations in modules.items():
                if module_name not in mr.modules:
                        raise Exception("Module %s cannot be found" % module_name)
                module = Module(module_name, None, None)
                module.instance = mr.modules[module_name]
                module._update_env(change_env)
                module._process_operations(operations)
                steps.append(module)
        change = Change(change_cfg['name'], steps, change_cfg['description'],
                        change_env)
        runner = ChangeRunner(change, self.modules_dir, self.artifacts_dir)
        try:
            runner.run()
        except:
            raise
        finally:
            runner.print_result_report()
Example #9
0
    def _process_change(self, change_cfg, fetch_only):
        logger.info("processing change %s" % change_cfg['name'])
        change_env = self._create_env_dict(change_cfg.get('environment'))
        if 'description' not in change_cfg:
            change_cfg['description'] = None
        mr = ModuleManager(self.modules_dir, self.artifacts_dir)

        if 'modules' in change_cfg:
            for module in change_cfg['modules']:
                url = module['url']
                ver = module['version'] if 'version' in module else None
                override = module['override'] if 'override' in module else False
                mr.install_module(url, ver, override)

        if fetch_only:
            artifacts = {}
            for _, module in mr.modules.items():
                for _, artifact in module.artifacts.items():
                    artifacts[artifact.filename] = artifact.hash
            return artifacts

        steps = []
        for modules in change_cfg['changes']:
            for module_name, operations in modules.items():
                if module_name not in mr.modules:
                    raise Exception("Module %s cannot be found" % module_name)
                module = Module(module_name, None, None)
                module.instance = mr.modules[module_name]
                module._update_env(change_env)
                module._process_operations(operations)
                steps.append(module)
        change = Change(change_cfg['name'], steps, change_cfg['description'],
                        change_env)
        runner = ChangeRunner(change, self.modules_dir, self.artifacts_dir)
        try:
            runner.run()
        except:
            raise
        finally:
            runner.print_result_report()
Example #10
0
 def run(self):
     self.setup_arguments()
     env_changes = None
     changes = []
     try:
         env_changes = os.environ['CCT_CHANGES']
     except KeyError:
         pass
     if len(sys.argv) < 2:
         self.parser.print_help()
         sys.exit(1)
     args = self.parser.parse_args()
     if args.get_changes:
         changes += urllib2.urlopen(args.get_changes).read().split('\n')
     if args.verbose:
         setup_logging(level=logging.DEBUG)
     elif args.quiet:
         setup_logging(level=logging.ERROR)
     else:
         setup_logging(level=logging.INFO)
     modules = ModuleManager(args.modules_dir, args.artifacts_dir)
     if args.list:
         modules.discover_modules()
         modules.list()
     elif args.show:
         modules.discover_modules()
         modules.list_module_oper(args.show)
     else:
         # env changes overrides cmdline ones
         # seems odd but really needed for containers - changes are passed
         # via docker run -e
         if env_changes:
             changes += env_changes.split()
         else:
             changes += args.changes
         try:
             self.process_changes(changes, args.modules_dir, args.artifacts_dir)
         except KeyboardInterrupt:
             pass
         except Exception:
             logger.error("CCT failed, check logs above for errors")
             exit(1)
     if args.command:
         self.exec_command(args.command)
Example #11
0
 def test_module_version_conflict(self):
     url = "https://github.com/containers-tools/test-module-dep"
     mod_dir = tempfile.mkdtemp()
     mm = ModuleManager(mod_dir, '/tmp')
     mm.install_module(url, 'master')
     with self.assertRaisesRegexp(Exception, 'Conflicting module.*'):
         mm.install_module(url, '1.0')
     shutil.rmtree(mod_dir)
Example #12
0
    def _process_change(self, change_cfg):
        if 'name' not in change_cfg:
            change_cfg['name'] = ''
        logger.info("processing change %s" % change_cfg['name'])
        change_env = self._create_env_dict(change_cfg.get('environment'))
        if 'description' not in change_cfg:
            change_cfg['description'] = None
        mr = ModuleManager(self.modules_dir, self.artifacts_dir)

        if 'modules' in change_cfg:
            for module in change_cfg['modules']:
                url = module['url']
                ver = module['version'] if 'version' in module else None
                override = module['override'] if 'override' in module else False
                mr.install_module(url, ver, override)

        if cfg.dogen:
            return

        steps = []
        for modules in change_cfg['changes']:
            for module_name, operations in modules.items():
                if module_name not in mr.modules:
                    msg = "Module %s cannot be found" % module_name
                    logger.error(msg)
                    raise Exception(msg)
                module = Module(module_name, None, None)
                module.instance = mr.modules[module_name]
                module._update_env(change_env)
                module._process_operations(operations)
                steps.append(module)
        change = Change(change_cfg['name'], steps, change_cfg['description'],
                        change_env)
        runner = ChangeRunner(change, self.modules_dir, self.artifacts_dir)
        try:
            runner.run()
        except:
            raise
Example #13
0
 def test_module_version_override(self):
     url = "https://github.com/containers-tools/test-module-dep"
     mod_dir = tempfile.mkdtemp()
     mm = ModuleManager(mod_dir, '/tmp')
     mm.install_module(url, '1.0', override=True)
     mm.install_module(url, 'master')
     self.assertEquals(mm.modules['test-module-dep.dummy'].version, '1.0')
     self.assertTrue(mm.modules['test-module-dep.dummy'].override)
     shutil.rmtree(mod_dir)
Example #14
0
 def test_find_modules(self):
     path = os.path.abspath(os.path.dirname(cct.module.__file__)) + "/modules"
     module_manager = ModuleManager(path, '/tmp')
     module_manager.discover_modules()
Example #15
0
 def __init__(self, change, modules_dir, artifacts_dir):
     self.change = change
     self.modules = ModuleManager(modules_dir, artifacts_dir)
     self.results = []
     self.cct_resource = {}
Example #16
0
 def test_find_modules(self):
     path = os.path.abspath(os.path.dirname(
         cct.module.__file__)) + "/modules"
     module_manager = ModuleManager(path, '/tmp')
     module_manager.discover_modules()