Пример #1
0
    def __init__(self, *args, **kwargs):
        config = json.loads(open('/etc/imagefactory/imagefactory.conf').read())
        config['plugins'] = '/etc/imagefactory/plugins.d'
        config['timeout'] = 3600
        config['rhevm_image_format'] = 'qcow2'
        ApplicationConfiguration(configuration=config)
        plugin_mgr = PluginManager('/etc/imagefactory/plugins.d')
        plugin_mgr.load()

        logfile = os.path.join(kwargs['workdir'], 'imgfac.log')

        print "ImgFacBuilder logging to: " + logfile
        self.fhandler = logging.FileHandler(logfile)
        self.tlog = logging.getLogger()
        self.tlog.setLevel(logging.DEBUG)
        self.tlog.addHandler(self.fhandler)
 
        global verbosemode
        if verbosemode:
            ch = logging.StreamHandler(sys.stdout)
            ch.setLevel(logging.DEBUG)
            formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
            ch.setFormatter(formatter)
            self.tlog.addHandler(ch)

        pass
Пример #2
0
 def setUp(self):
     # create the info file for an OS plugin
     self.os_info_file = tempfile.NamedTemporaryFile(mode='w',
                                                     suffix='.info',
                                                     prefix='ifut-')
     json.dump(INFO1, self.os_info_file)
     self.os_info_file.flush()
     os.fsync(self.os_info_file)
     self.os_plugin_name = os.path.basename(
         self.os_info_file.name).partition('.')[0]
     # create a module for this plugin
     os.mkdir(os.path.join(tempfile.gettempdir(), self.os_plugin_name),
              0o744)
     osclass = open(
         os.path.join(tempfile.gettempdir(), self.os_plugin_name,
                      self.os_plugin_name + '.py'), 'w')
     osclass.write('class %s(object):\n    pass' % self.os_plugin_name)
     osclass.close()
     osinit = open(
         os.path.join(tempfile.gettempdir(), self.os_plugin_name,
                      '__init__.py'), 'w')
     osinit.write('from %s import %s as delegate_class' %
                  (self.os_plugin_name, self.os_plugin_name))
     osinit.close()
     # create the info file for a CLOUD plugin
     self.cloud_info_file = tempfile.NamedTemporaryFile(mode='w',
                                                        suffix='.info',
                                                        prefix='ifut-')
     json.dump(INFO2, self.cloud_info_file)
     self.cloud_info_file.flush()
     os.fsync(self.cloud_info_file)
     self.cloud_plugin_name = os.path.basename(
         self.cloud_info_file.name).partition('.')[0]
     # create a module for this plugin
     os.mkdir(os.path.join(tempfile.gettempdir(), self.cloud_plugin_name),
              0o744)
     cloudclass = open(
         os.path.join(tempfile.gettempdir(), self.cloud_plugin_name,
                      self.cloud_plugin_name + '.py'), 'w')
     cloudclass.write('class %s(object):\n    pass' %
                      self.cloud_plugin_name)
     cloudclass.close()
     cloudinit = open(
         os.path.join(tempfile.gettempdir(), self.cloud_plugin_name,
                      '__init__.py'), 'w')
     cloudinit.write('from %s import %s as delegate_class' %
                     (self.cloud_plugin_name, self.cloud_plugin_name))
     cloudinit.close()
     # get a PluginManager instance and load plugin .info files
     self.plugin_mgr = PluginManager(plugin_path=tempfile.gettempdir())
     self.plugin_mgr.load()
Пример #3
0
def get_plugins(plugin_id=None):
    try:
        response.status = 200
        plugin_mgr = PluginManager()
        if (plugin_id):
            plugin = plugin_mgr.plugins[plugin_id].copy()
            plugin.update({
                '_type': 'plugin',
                'id': plugin_id,
                'href': '%s/%s' % (request.url, plugin_id)
            })
            return converted_response(plugin)
        else:
            plugins = plugin_mgr.plugins.copy()
            for plugin in plugins:
                plugins[plugin].update({
                    '_type': 'plugin',
                    'id': plugin,
                    'href': '%s/%s' % (request.url, plugin)
                })
        return converted_response({'plugins': list(plugins.values())})
    except Exception as e:
        log.exception(e)
        raise HTTPResponse(status=500,
                           output='%s %s' % (e, traceback.format_exc()))
    def __init__(self, *args, **kwargs):
        config = json.loads(open('/etc/imagefactory/imagefactory.conf').read())
        config['plugins'] = '/etc/imagefactory/plugins.d'
        config['timeout'] = 3600
        ApplicationConfiguration(configuration=config)
        plugin_mgr = PluginManager('/etc/imagefactory/plugins.d')
        plugin_mgr.load()

        logfile = os.path.join(kwargs['workdir'], 'imgfac.log')

        self.fhandler = logging.FileHandler(logfile)
        self.tlog = logging.getLogger()
        self.tlog.setLevel(logging.DEBUG)
        self.tlog.addHandler(self.fhandler)

        pass
Пример #5
0
 def setUp(self):
     # create the info file for an OS plugin
     self.os_info_file = tempfile.NamedTemporaryFile(mode='w', suffix='.info', prefix='ifut-')
     json.dump(INFO1, self.os_info_file)
     self.os_info_file.flush()
     os.fsync(self.os_info_file)
     self.os_plugin_name = os.path.basename(self.os_info_file.name).partition('.')[0]
     # create a module for this plugin
     os.mkdir(os.path.join(tempfile.gettempdir(), self.os_plugin_name), 0744)
     osclass = open(os.path.join(tempfile.gettempdir(), self.os_plugin_name, self.os_plugin_name + '.py'), 'w')
     osclass.write('class %s(object):\n    pass' % self.os_plugin_name)
     osclass.close()
     osinit = open(os.path.join(tempfile.gettempdir(), self.os_plugin_name, '__init__.py'), 'w')
     osinit.write('from %s import %s as delegate_class' % (self.os_plugin_name, self.os_plugin_name))
     osinit.close()
     # create the info file for a CLOUD plugin
     self.cloud_info_file = tempfile.NamedTemporaryFile(mode='w', suffix='.info', prefix='ifut-')
     json.dump(INFO2, self.cloud_info_file)
     self.cloud_info_file.flush()
     os.fsync(self.cloud_info_file)
     self.cloud_plugin_name = os.path.basename(self.cloud_info_file.name).partition('.')[0]
     # create a module for this plugin
     os.mkdir(os.path.join(tempfile.gettempdir(), self.cloud_plugin_name), 0744)
     cloudclass = open(os.path.join(tempfile.gettempdir(), self.cloud_plugin_name, self.cloud_plugin_name + '.py'), 'w')
     cloudclass.write('class %s(object):\n    pass' % self.cloud_plugin_name)
     cloudclass.close()
     cloudinit = open(os.path.join(tempfile.gettempdir(), self.cloud_plugin_name, '__init__.py'), 'w')
     cloudinit.write('from %s import %s as delegate_class' % (self.cloud_plugin_name, self.cloud_plugin_name))
     cloudinit.close()
     # get a PluginManager instance and load plugin .info files
     self.plugin_mgr = PluginManager(plugin_path=tempfile.gettempdir())
     self.plugin_mgr.load()
Пример #6
0
    def __init__(self, *args, **kwargs):
        config = json.loads(open('/etc/imagefactory/imagefactory.conf').read())
        config['plugins'] = '/etc/imagefactory/plugins.d'
        config['timeout'] = 3600
        ApplicationConfiguration(configuration=config)
        plugin_mgr = PluginManager('/etc/imagefactory/plugins.d')
        plugin_mgr.load()

        logfile = os.path.join(kwargs['workdir'], 'imgfac.log')

        self.fhandler = logging.FileHandler(logfile)
        self.tlog = logging.getLogger()
        self.tlog.setLevel(logging.DEBUG)
        self.tlog.addHandler(self.fhandler)

        pass
    def __init__(self, *args, **kwargs):
        config = json.loads(open('/etc/imagefactory/imagefactory.conf').read())
        config['plugins'] = '/etc/imagefactory/plugins.d'
        config['timeout'] = 3600
        config['rhevm_image_format'] = 'qcow2'
        ApplicationConfiguration(configuration=config)
        plugin_mgr = PluginManager('/etc/imagefactory/plugins.d')
        plugin_mgr.load()

        self.fhandler = logging.StreamHandler(sys.stdout)
        self.tlog = logging.getLogger()
        self.tlog.setLevel(logging.DEBUG)
        self.tlog.addHandler(self.fhandler)
        verbosemode = kwargs.get('verbosemode', False)

        if verbosemode:
            ch = logging.StreamHandler(sys.stdout)
            ch.setLevel(logging.DEBUG)
            formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
            ch.setFormatter(formatter)
            self.tlog.addHandler(ch)

        pass
    def __init__(self, *args, **kwargs):
        config = json.loads(open('/etc/imagefactory/imagefactory.conf').read())
        config['plugins'] = '/etc/imagefactory/plugins.d'
        config['timeout'] = 3600
        config['rhevm_image_format'] = 'qcow2'
        ApplicationConfiguration(configuration=config)
        plugin_mgr = PluginManager('/etc/imagefactory/plugins.d')
        plugin_mgr.load()

        self.fhandler = logging.StreamHandler(sys.stdout)
        self.tlog = logging.getLogger()
        self.tlog.setLevel(logging.DEBUG)
        self.tlog.addHandler(self.fhandler)
        verbosemode = kwargs.get('verbosemode', False)

        if verbosemode:
            ch = logging.StreamHandler(sys.stdout)
            ch.setLevel(logging.DEBUG)
            formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
            ch.setFormatter(formatter)
            self.tlog.addHandler(ch)

        pass
Пример #9
0
    def __init__(self, *args, **kwargs):
        config = json.loads(open("/etc/imagefactory/imagefactory.conf").read())
        config["plugins"] = "/etc/imagefactory/plugins.d"
        config["timeout"] = 3600
        config["rhevm_image_format"] = "qcow2"
        ApplicationConfiguration(configuration=config)
        plugin_mgr = PluginManager("/etc/imagefactory/plugins.d")
        plugin_mgr.load()

        self.fhandler = logging.StreamHandler(sys.stdout)
        self.tlog = logging.getLogger()
        self.tlog.setLevel(logging.DEBUG)
        self.tlog.addHandler(self.fhandler)
        verbosemode = kwargs.get("verbosemode", False)

        if verbosemode:
            ch = logging.StreamHandler(sys.stdout)
            ch.setLevel(logging.DEBUG)
            formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
            ch.setFormatter(formatter)
            self.tlog.addHandler(ch)

        pass
Пример #10
0
class testPluginManager(unittest.TestCase):
    """ TODO: Docstring for testPluginManager  """
    def __init__(self, methodName='runTest'):
        super(testPluginManager, self).__init__(methodName)
        logging.basicConfig(level=logging.NOTSET,
                            format='%(asctime)s \
                                    %(levelname)s \
                                    %(name)s \
                                    pid(%(process)d) \
                                    Message: %(message)s',
                            filename='/tmp/testPluginManager.log')

    def setUp(self):
        # create the info file for an OS plugin
        self.os_info_file = tempfile.NamedTemporaryFile(mode='w',
                                                        suffix='.info',
                                                        prefix='ifut-')
        json.dump(INFO1, self.os_info_file)
        self.os_info_file.flush()
        os.fsync(self.os_info_file)
        self.os_plugin_name = os.path.basename(
            self.os_info_file.name).partition('.')[0]
        # create a module for this plugin
        os.mkdir(os.path.join(tempfile.gettempdir(), self.os_plugin_name),
                 0o744)
        osclass = open(
            os.path.join(tempfile.gettempdir(), self.os_plugin_name,
                         self.os_plugin_name + '.py'), 'w')
        osclass.write('class %s(object):\n    pass' % self.os_plugin_name)
        osclass.close()
        osinit = open(
            os.path.join(tempfile.gettempdir(), self.os_plugin_name,
                         '__init__.py'), 'w')
        osinit.write('from %s import %s as delegate_class' %
                     (self.os_plugin_name, self.os_plugin_name))
        osinit.close()
        # create the info file for a CLOUD plugin
        self.cloud_info_file = tempfile.NamedTemporaryFile(mode='w',
                                                           suffix='.info',
                                                           prefix='ifut-')
        json.dump(INFO2, self.cloud_info_file)
        self.cloud_info_file.flush()
        os.fsync(self.cloud_info_file)
        self.cloud_plugin_name = os.path.basename(
            self.cloud_info_file.name).partition('.')[0]
        # create a module for this plugin
        os.mkdir(os.path.join(tempfile.gettempdir(), self.cloud_plugin_name),
                 0o744)
        cloudclass = open(
            os.path.join(tempfile.gettempdir(), self.cloud_plugin_name,
                         self.cloud_plugin_name + '.py'), 'w')
        cloudclass.write('class %s(object):\n    pass' %
                         self.cloud_plugin_name)
        cloudclass.close()
        cloudinit = open(
            os.path.join(tempfile.gettempdir(), self.cloud_plugin_name,
                         '__init__.py'), 'w')
        cloudinit.write('from %s import %s as delegate_class' %
                        (self.cloud_plugin_name, self.cloud_plugin_name))
        cloudinit.close()
        # get a PluginManager instance and load plugin .info files
        self.plugin_mgr = PluginManager(plugin_path=tempfile.gettempdir())
        self.plugin_mgr.load()

    def tearDown(self):
        self.plugin_mgr = None
        shutil.rmtree(path=os.path.join(tempfile.gettempdir(),
                                        self.os_plugin_name),
                      ignore_errors=True)
        shutil.rmtree(path=os.path.join(tempfile.gettempdir(),
                                        self.cloud_plugin_name),
                      ignore_errors=True)
        self.os_info_file.close()
        self.cloud_info_file.close()

    def testMetadataForPlugin(self):
        os_metadata = self.plugin_mgr.metadata_for_plugin(self.os_plugin_name)
        self.assertDictEqual(os_metadata, INFO1)
        cloud_metadata = self.plugin_mgr.metadata_for_plugin(
            self.cloud_plugin_name)
        self.assertDictEqual(cloud_metadata, INFO2)

    @unittest.skip('See comments in code.')
    def testPluginForTarget(self):
        # This code is flawed...
        os_plugin = self.plugin_mgr.plugin_for_target(
            ('osfoo', 'osbar', 'osbaz'))
        self.assertEqual(os_plugin.__class__.__name__, self.os_plugin_name)
        cloud_plugin = self.plugin_mgr.plugin_for_target(
            ('cloudfoo', 'cloudbar', 'cloudbaz'))
        self.assertEqual(cloud_plugin.__class__.__name__,
                         self.cloud_plugin_name)
Пример #11
0
class testPluginManager(unittest.TestCase):
    """ TODO: Docstring for testPluginManager  """

    def __init__(self, methodName='runTest'):
        super(testPluginManager, self).__init__(methodName)
        logging.basicConfig(level=logging.NOTSET,
                            format='%(asctime)s \
                                    %(levelname)s \
                                    %(name)s \
                                    pid(%(process)d) \
                                    Message: %(message)s', 
                            filename='/tmp/testPluginManager.log')

    def setUp(self):
        # create the info file for an OS plugin
        self.os_info_file = tempfile.NamedTemporaryFile(mode='w', suffix='.info', prefix='ifut-')
        json.dump(INFO1, self.os_info_file)
        self.os_info_file.flush()
        os.fsync(self.os_info_file)
        self.os_plugin_name = os.path.basename(self.os_info_file.name).partition('.')[0]
        # create a module for this plugin
        os.mkdir(os.path.join(tempfile.gettempdir(), self.os_plugin_name), 0744)
        osclass = open(os.path.join(tempfile.gettempdir(), self.os_plugin_name, self.os_plugin_name + '.py'), 'w')
        osclass.write('class %s(object):\n    pass' % self.os_plugin_name)
        osclass.close()
        osinit = open(os.path.join(tempfile.gettempdir(), self.os_plugin_name, '__init__.py'), 'w')
        osinit.write('from %s import %s as delegate_class' % (self.os_plugin_name, self.os_plugin_name))
        osinit.close()
        # create the info file for a CLOUD plugin
        self.cloud_info_file = tempfile.NamedTemporaryFile(mode='w', suffix='.info', prefix='ifut-')
        json.dump(INFO2, self.cloud_info_file)
        self.cloud_info_file.flush()
        os.fsync(self.cloud_info_file)
        self.cloud_plugin_name = os.path.basename(self.cloud_info_file.name).partition('.')[0]
        # create a module for this plugin
        os.mkdir(os.path.join(tempfile.gettempdir(), self.cloud_plugin_name), 0744)
        cloudclass = open(os.path.join(tempfile.gettempdir(), self.cloud_plugin_name, self.cloud_plugin_name + '.py'), 'w')
        cloudclass.write('class %s(object):\n    pass' % self.cloud_plugin_name)
        cloudclass.close()
        cloudinit = open(os.path.join(tempfile.gettempdir(), self.cloud_plugin_name, '__init__.py'), 'w')
        cloudinit.write('from %s import %s as delegate_class' % (self.cloud_plugin_name, self.cloud_plugin_name))
        cloudinit.close()
        # get a PluginManager instance and load plugin .info files
        self.plugin_mgr = PluginManager(plugin_path=tempfile.gettempdir())
        self.plugin_mgr.load()

    def tearDown(self):
        self.plugin_mgr = None
        shutil.rmtree(path=os.path.join(tempfile.gettempdir(), self.os_plugin_name), ignore_errors=True)
        shutil.rmtree(path=os.path.join(tempfile.gettempdir(), self.cloud_plugin_name), ignore_errors=True)
        self.os_info_file.close()
        self.cloud_info_file.close()

    def testMetadataForPlugin(self):
        os_metadata = self.plugin_mgr.metadata_for_plugin(self.os_plugin_name)
        self.assertDictEqual(os_metadata, INFO1)
        cloud_metadata = self.plugin_mgr.metadata_for_plugin(self.cloud_plugin_name)
        self.assertDictEqual(cloud_metadata, INFO2)

    @unittest.skip('See comments in code.')
    def testPluginForTarget(self):
        # This code is flawed...
        os_plugin = self.plugin_mgr.plugin_for_target(('osfoo', 'osbar', 'osbaz'))
        self.assertEqual(os_plugin.__class__.__name__, self.os_plugin_name)
        cloud_plugin = self.plugin_mgr.plugin_for_target(('cloudfoo', 'cloudbar', 'cloudbaz'))
        self.assertEqual(cloud_plugin.__class__.__name__, self.cloud_plugin_name)