def setUp(self):
     super(TestOSMatcher, self).setUp()
     self.item_matcher = progress_calculator\
         .OS_INSTALLER_CONFIGURATIONS[
             'CentOS'
         ]
     logsetting.init()
Esempio n. 2
0
def main():
    """main entry."""
    flags.init()
    logsetting.init()
    databags = []
    databags_dir = flags.OPTIONS.databags_dir
    for item in os.listdir(databags_dir):
        databags.append(item)

    for databag in databags:
        logging.info('add databag %s', databag)
        cmd = "knife data bag create %s" % databag
        os.system(cmd)
        databag_items = []
        databagitem_dir = os.path.join(databags_dir, databag)
        for item in os.listdir(databagitem_dir):
            if item.endswith('.json'):
                databag_items.append(os.path.join(databagitem_dir, item))
            else:
                logging.info('ignore %s in %s', item, databagitem_dir)

        for databag_item in databag_items:
            logging.info('add databag item %s to databag %s',
                         databag_item, databag)
            cmd = 'knife data bag from file %s %s' % (databag, databag_item)
            status = os.system(cmd)
            logging.info('run cmd %s returns %s', cmd, status)
            if status:
                sys.exit(1)
 def setUp(self):
     super(TestOSMatcher, self).setUp()
     logsetting.init()
     file_matchers = [
         FileMatcher(
             min_progress=0.6,
             max_progress=0.9,
             filename='test_log',
             line_matchers={
                 'start': LineMatcher(
                     pattern=r'',
                     severity='',
                 )
             }
         )
     ]
     self.item_matcher = adapter_matcher.AdapterItemMatcher(file_matchers)
     file_reader_factory = FileReaderFactory(
         logdir=os.path.dirname(
             os.path.abspath(__file__)) + '/data'
     )
     self.os_matcher = adapter_matcher.OSMatcher(
         os_installer_name='cobbler',
         os_pattern=r'CentOS.*',
         item_matcher=self.item_matcher,
         file_reader_factory=file_reader_factory
     )
Esempio n. 4
0
def main(argv):
    flags.init()
    logsetting.init()
    clusterids = [
        int(clusterid) for clusterid in flags.OPTIONS.clusterids.split(',')
        if clusterid
    ]
    with database.session() as session:
        if not clusterids:
            clusters = session.query(Cluster).all()
            trigger_clusterids  = [cluster.id for cluster in clusters]
        else:
            trigger_clusterids = clusterids

        logging.info('trigger installer for clusters: %s',
                     trigger_clusterids)
        for clusterid in trigger_clusterids:
            hosts = session.query(
                ClusterHost).filter_by(
                cluster_id=clsuterid).all()
            hostids = [host.id for host in hosts]
            if flags.OPTIONS.async:
                celery.send_task('compass.tasks.trigger_install',
                                 (clusterid, hostids))
            else:
                trigger_install.trigger_install(clusterid, hostids)
 def setUp(self):
     super(TestPackageMatcher, self).setUp()
     logsetting.init()
     file_matchers = [
         FileMatcher(
             min_progress=0.6,
             max_progress=0.9,
             filename='test_log',
             line_matchers={
                 'start': LineMatcher(
                     pattern=r'',
                     severity='',
                 )
             }
         )
     ]
     self.item_matcher = adapter_matcher.AdapterItemMatcher(file_matchers)
     self.file_reader_factory = FileReaderFactory(
         logdir=os.path.dirname(
             os.path.abspath(__file__)) + '/data'
     )
     self.package_matcher = adapter_matcher.PackageMatcher(
         package_installer_name='chef',
         distributed_system_pattern=r'openstack',
         item_matcher=self.item_matcher,
         file_reader_factory=self.file_reader_factory
     )
Esempio n. 6
0
 def setUp(self):
     super(HDManagerTest, self).setUp()
     logsetting.init()
     self.manager = HDManager()
     self.correct_host = '33.33.33.1'
     self.correct_host_2 = '127.0.0.1'
     self.correct_credential = {'version': '2c', 'community': 'public'}
 def setUp(self):
     super(TestEndToEnd, self).setUp()
     logsetting.init()
     database.create_db()
     self._mock_lock()
     os.system = mock.Mock()
     self.progress_checker_ = {}
Esempio n. 8
0
def main():
    flags.init()
    logsetting.init()
    client = _get_client()
    _login(client)
    if flags.OPTIONS.poll_switches:
        machines = _poll_switches(client)
    else:
        machines = _get_machines(client)
    logging.info('machines are %s', machines)
    subnet_mapping = _add_subnets(client)
    adapter_id, os_id, distributed_system_id, flavor_id = _get_adapter(client)
    cluster_id, host_mapping, role_mapping = _add_cluster(
        client, adapter_id, os_id, flavor_id, machines)
    host_ips = _set_host_networking(
        client, host_mapping, subnet_mapping
    )
    _set_cluster_os_config(client, cluster_id, host_ips)
    if distributed_system_id:
        _set_cluster_package_config(client, cluster_id)
    if role_mapping:
        _set_hosts_roles(client, cluster_id, host_mapping, role_mapping)
    _deploy_clusters(client, cluster_id, host_mapping)
    _get_installing_progress(client, cluster_id, host_mapping)
    _check_dashboard_links(client, cluster_id)
 def setUp(self):
     super(TestPackageMatcher, self).setUp()
     self.item_matcher = progress_calculator\
         .PACKAGE_INSTALLER_CONFIGURATIONS[
             'openstack'
         ]
     logsetting.init()
    def setUp(self):
        super(AuthTestCase, self).setUp()
        logsetting.init()
        database.init(self.DATABASE_URL)
        database.create_db()

        self.test_client = app.test_client()
Esempio n. 11
0
def main():
    """Compass cli entry point."""
    flags.init()
    logsetting.init()
    database.init()
    cli = BootCLI()
    output = cli.run(sys.argv)
    return sys.exit(output)
Esempio n. 12
0
 def setUp(self):
     super(TestIncrementalProgress, self).setUp()
     logsetting.init()
     self.log_history = {
         'percentage': 0.5,
         'message': '',
         'severity': ''
     }
Esempio n. 13
0
def global_celery_init(**_):
    """Initialization code."""
    flags.init()
    flags.OPTIONS.logfile = setting.CELERY_LOGFILE
    logsetting.init()
    database.init()
    adapter_api.load_adapters()
    metadata_api.load_metadatas()
Esempio n. 14
0
def global_celery_init(**_):
    """Initialization code."""
    flags.init()
    flags.OPTIONS.logfile = setting.CELERY_LOGFILE
    logsetting.init()
    database.init()
    adapter_api.load_adapters()
    metadata_api.load_metadatas()
    adapter_api.load_flavors()
    progress_calculator.load_calculator_configurations()
Esempio n. 15
0
def main():
    """main entry."""
    flags.init()
    logsetting.init()
    cookbooks_dir = flags.OPTIONS.cookbooks_dir
    logging.info('add cookbooks %s', cookbooks_dir)
    cmd = "knife cookbook upload --all --cookbook-path %s" % cookbooks_dir
    status = os.system(cmd)
    logging.info('run cmd %s returns %s', cmd, status)
    if status:
        sys.exit(1)
 def setUp(self):
     super(TestAdapterMatcher, self).setUp()
     self.os_item_matcher = progress_calculator\
         .OS_INSTALLER_CONFIGURATIONS[
             'CentOS'
         ]
     self.package_item_matcher = progress_calculator\
         .PACKAGE_INSTALLER_CONFIGURATIONS[
             'openstack'
         ]
     logsetting.init()
     database.create_db()
 def setUp(self):
     super(TestConfigFilter, self).setUp()
     logsetting.init()
     self.config_ = {
         '1': '1',
         '2': {
             '22': '22',
             '33': {
                 '333': '333',
                 '44': '444'
             }
         },
         '3': {'33': '44'}
     }
Esempio n. 18
0
def main():
    flags.init()
    logsetting.init()
    client = _get_client()
    if flags.OPTIONS.poll_switches:
        machines = _poll_switches(client)
    else:
        machines = _get_machines(client)

    adapter_id = _get_adapter(client)
    cluster_hosts = _add_cluster(client, adapter_id, machines)
    _set_cluster_security(client, cluster_hosts)
    _set_cluster_networking(client, cluster_hosts)
    _set_cluster_partition(client, cluster_hosts)
    _set_host_config(client, cluster_hosts)
    _deploy_clusters(client, cluster_hosts)
    _get_installing_progress(client, cluster_hosts)
    _check_dashboard_links(client, cluster_hosts)
    def setUp(self):
        super(TestPollSwitch, self).setUp()
        logsetting.init()
        database.init(self.DATABASE_URL)
        database.create_db()
        self.test_client = app.test_client()

        with database.session() as session:
            # Add one switch to DB
            switch = Switch(ip="127.0.0.1",
                            credential=self.SWITCH_CREDENTIAL)
            session.add(switch)
            # Add filter port to SwitchConfig table
            filter_list = [
                SwitchConfig(ip="127.0.0.1", filter_port='6'),
                SwitchConfig(ip="127.0.0.1", filter_port='7')
            ]
            session.add_all(filter_list)
Esempio n. 20
0
    def setUp(self):
        super(ApiTestCase, self).setUp()
        database.init(self.DATABASE_URL)
        database.create_db()
        self.app = app.test_client()

        # We do not want to send a real task as our test environment
        # does not have a AMQP system set up. TODO(): any better way?
        current_app.send_task = Mock()

        # We do not want to send a real task as our test environment
        # does not have a AMQP system set up. TODO(): any better way?
        current_app.send_task = Mock()
        self.backup_logfile = flags.OPTIONS.logfile
        if not flags.OPTIONS.logfile:
            flags.OPTIONS.logfile = '/tmp/test_api.log'

        logsetting.init()
    def setUp(self):
        super(TestEndToEnd, self).setUp()
        database.create_db()
        shutil.rmtree = Mock()
        os.system = Mock()
        self.os_installer_mock_ = {}
        self.os_installer_mock_['cobbler'] = self._mock_cobbler
        self.package_installer_mock_ = {}
        self.package_installer_mock_['chef'] = self._mock_chef
        self.os_installer_checker_ = {}
        self.os_installer_checker_['cobbler'] = self._check_cobbler
        self.package_installer_checker_ = {}
        self.package_installer_checker_['chef'] = self._check_chef
        self.backup_logfile = flags.OPTIONS.logfile
        if not flags.OPTIONS.logfile:
            flags.OPTIONS.logfile = '/tmp/test_trigger_install.log'

        logsetting.init()
Esempio n. 22
0
def main():
    """main entry."""
    flags.init()
    logsetting.init()
    rolelist = []
    roles_dir = flags.OPTIONS.roles_dir

    for item in os.listdir(roles_dir):
        role_file = os.path.join(roles_dir, item)
        rolelist.append(role_file)

    for role in rolelist:
        logging.info('add role %s', role)
        cmd = "knife role from file %s" % role
        status = os.system(cmd)
        logging.info('run cmd %s returns %s', cmd, status)
        if status:
            sys.exit(1)
Esempio n. 23
0
def main():
    """main entry."""
    flags.init()
    logsetting.init()
    rolelist = []
    roles_dir = flags.OPTIONS.roles_dir

    for item in os.listdir(roles_dir):
        if item.endswith('.rb') or item.endswith('.json'):
            rolelist.append(os.path.join(roles_dir, item))
        else:
            logging.info('ignore %s in %s', item, roles_dir)

    for role in rolelist:
        logging.info('add role %s', role)
        cmd = "knife role from file %s" % role
        status = os.system(cmd)
        logging.info('run cmd %s returns %s', cmd, status)
        if status:
            sys.exit(1)
 def setUp(self):
     """test setup."""
     super(TestEndToEnd, self).setUp()
     self._mock_setting()
     logsetting.init()
     database.create_db()
     self._mock_lock()
     self.rmtree_backup_ = shutil.rmtree
     shutil.rmtree = mock.Mock()
     self.system_backup_ = os.system
     os.system = mock.Mock()
     self.os_installer_mock_ = {}
     self.os_installer_mock_['cobbler'] = self._mock_cobbler
     self.os_installer_unmock_ = {}
     self.os_installer_unmock_['cobbler'] = self._unmock_cobbler
     self.package_installer_mock_ = {}
     self.package_installer_mock_['chef'] = self._mock_chef
     self.package_installer_unmock_ = {}
     self.package_installer_unmock_['chef'] = self._unmock_chef
     self.os_installer_checker_ = {}
     self.os_installer_checker_['cobbler'] = self._check_cobbler
     self.package_installer_checker_ = {}
     self.package_installer_checker_['chef'] = self._check_chef
 def setUp(self):
     super(TestProgressCalculator, self).setUp()
     parent_path = os.path.abspath(os.path.join(
         os.path.dirname(__file__), "../../../.."
     ))
     setting.CONFIG_DIR = os.path.join(parent_path, 'conf')
     logsetting.init()
     self._mock_lock()
     database.init('sqlite://')
     database.create_db()
     self.backup_cobbler_installation_dir = (
         setting.COBBLER_INSTALLATION_LOGDIR
     )
     self.backup_chef_installation_dir = setting.CHEF_INSTALLATION_LOGDIR
     self.backup_installation_dir = setting.INSTALLATION_LOGDIR
     self.tmp_logpath = os.path.join('/tmp/mocklogs', str(uuid.uuid4()))
     setting.COBBLER_INSTALLATION_LOGDIR = self.tmp_logpath
     setting.CHEF_INSTALLATION_LOGDIR = self.tmp_logpath
     setting.INSTALLATION_LOGDIR = {
         'CobblerInstaller': setting.COBBLER_INSTALLATION_LOGDIR,
         'ChefInstaller': setting.CHEF_INSTALLATION_LOGDIR
     }
     reload(progress_calculator)
Esempio n. 26
0
 def setUp(self):
     super(TestNoProxy, self).setUp()
     logsetting.init()
Esempio n. 27
0
 def setUp(self):
     super(TestOverrideIfEmpty, self).setUp()
     logsetting.init()
Esempio n. 28
0
 def setUp(self):
     super(TestInstallerFunctions, self).setUp()
     logsetting.init()
     self.installers_backup_ = os_installer.INSTALLERS
     os_installer.INSTALLERS = {}
Esempio n. 29
0
 def setUp(self):
     super(OVSMacTest, self).setUp()
     logsetting.init()
     self.host = '10.145.88.160'
     self.credential = {'username': '******', 'password': '******'}
            'match_nextline_next_matcher_name': 'mnn',
        }
        matcher = line_matcher.LineMatcher(
            **test_regex_match)
        expected = ('msn', 'mnn')
        self.assertEqual(
            expected,
            matcher.update_progress(
                line, progress))

    def test_wrong_message(self):
        line = 'abc'
        progress = line_matcher.Progress(
            progress=1, message='a', severity=' ')
        test_wrong_message = {
            'pattern': r'.*.',
            'message_template': 'Installing %(package)s'
        }
        matcher = line_matcher.LineMatcher(
            **test_wrong_message)
        self.assertRaises(
            KeyError,
            matcher.update_progress,
            line=line,
            progress=progress)

if __name__ == '__main__':
    flags.init()
    logsetting.init()
    unittest2.main()
Esempio n. 31
0
 def setUp(self):
     super(TestAssignRoles, self).setUp()
     logsetting.init()
     self.roles_ = ['control', 'api', 'compute']
     self.maxs_ = {'control': 1, 'api': 1, 'compute': -1}
     self.default_min_ = 1
Esempio n. 32
0
 def setUp(self):
     super(TestBaseSnmpMacPlugin, self).setUp()
     logsetting.init()
     self.test_plugin = BaseSnmpMacPlugin('12.0.0.1',
                                          {'version': '2c',
                                           'community': 'public'})
Esempio n. 33
0
 def setUp(self):
     super(TestDatabase, self).setUp()
     logsetting.init()
     database.init('sqlite://')
 def setUp(self):
     super(TestProgress, self).setUp()
     logsetting.init()
Esempio n. 35
0
 def setUp(self):
     super(TestDictMerge, self).setUp()
     logsetting.init()
 def setUp(self):
     super(TestProgressCalculator, self).setUp()
     logsetting.init()
     self._mock_progress()
 def setUp(self):
     super(TestFilterFileExist, self).setUp()
     logsetting.init()
Esempio n. 38
0
 def setUp(self):
     super(TestAssignFromPattern, self).setUp()
     logsetting.init()
Esempio n. 39
0
 def setUp(self):
     super(TestAssignIPs, self).setUp()
     logsetting.init()
 def setUp(self):
     super(TestLineMatcher, self).setUp()
     logsetting.init()
 def setUp(self):
     super(TestConfigMerger, self).setUp()
     logsetting.init()
 def setUp(self):
     super(TestCompositeFileFilter, self).setUp()
     self.file_path = os.path.dirname(os.path.abspath(__file__))
     logsetting.init()
Esempio n. 43
0
 def setUp(self):
     super(BaseTest, self).setUp()
     logsetting.init()
Esempio n. 44
0
def tasks_setup_logging(**_):
    """Setup logging options from compass setting."""
    flags.init()
    flags.OPTIONS.logfile = setting.CELERY_LOGFILE
    logsetting.init()
 def tearDown(self):
     flags.OPTIONS.logfile = self.backup_logfile
     logsetting.init()
     database.drop_db()
     super(TestEndToEnd, self).tearDown()
Esempio n. 46
0
 def setUp(self):
     super(HuaweiMacTest, self).setUp()
     logsetting.init()
     host = '192.168.1.1'
     credential = {'version': '2c', 'community': 'public'}
     self.mac_plugin = Mac(host, credential)
Esempio n. 47
0
 def setUp(self):
     super(HuaweiTest, self).setUp()
     logsetting.init()
     self.huawei = Huawei()
     self.sys_info = 'Huawei Technologies'
 def setUp(self):
     super(TestFileReader, self).setUp()
     logsetting.init()

class TestInstallerFunctions(unittest2.TestCase):
    def setUp(self):
        self.installers_backup = package_installer.INSTALLERS
        package_installer.INSTALLERS = {}

    def tearDown(self):
        package_installer.INSTALLERS = self.installers_backup

    def test_found_installer(self):
        package_installer.register(DummyInstaller)
        intaller = package_installer.get_installer_by_name(
            DummyInstaller.NAME)
        self.assertIsInstance(intaller, DummyInstaller)

    def test_notfound_unregistered_installer(self):
        self.assertRaises(KeyError, package_installer.get_installer_by_name,
                          DummyInstaller.NAME)

    def test_multi_registered_installer(self):
        package_installer.register(DummyInstaller)
        self.assertRaises(KeyError, package_installer.register,
                          Dummy2Installer)


if __name__ == '__main__':
    flags.init()
    logsetting.init()
    unittest2.main()
Esempio n. 50
0
def tasks_setup_logging(**_kw):
    '''setup logging options'''
    flags.init()
    flags.OPTIONS.logfile = setting.CELERY_LOGFILE
    logsetting.init()