Пример #1
0
    def setUp(self):
        super(MetadataTestCase, self).setUp()
        os.environ['COMPASS_IGNORE_SETTING'] = 'true'
        os.environ['COMPASS_CONFIG_DIR'] = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), 'data')
        reload(setting)
        database.init('sqlite://')
        database.create_db()
        adapter.load_adapters(force_reload=True)
        metadata.load_metadatas(force_reload=True)
        adapter.load_flavors(force_reload=True)

        # Get a os_id and adapter_id
        self.user_object = (user_api.get_user_object(
            setting.COMPASS_ADMIN_EMAIL))
        self.adapter_object = adapter.list_adapters(self.user_object)
        test_adapter = None
        for adapter_obj in self.adapter_object:
            if adapter_obj['name'] == 'openstack_icehouse':
                self.adapter_id = adapter_obj['id']
                test_adapter = adapter_obj
                break
        self.os_id = None
        if test_adapter['flavors']:
            for supported_os in test_adapter['supported_oses']:
                self.os_id = supported_os['os_id']
                break
            for flavor in test_adapter['flavors']:
                if flavor['name'] == 'HA-multinodes':
                    self.flavor_id = flavor['id']
                    break
Пример #2
0
    def setUp(self):
        super(AdapterTestCase, self).setUp()
        reload(setting)
        setting.CONFIG_DIR = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            'data'
        )
        database.init('sqlite://')
        database.create_db()
        self.user_object = (
            user_api.get_user_object(
                setting.COMPASS_ADMIN_EMAIL
            )
        )

        mock_config = mock.Mock()
        self.backup_adapter_configs = util.load_configs
        util.load_configs = mock_config
        configs = [{
            'NAME': 'openstack_test',
            'DISLAY_NAME': 'Test OpenStack Icehouse',
            'PACKAGE_INSTALLER': 'chef_installer',
            'OS_INSTALLER': 'cobbler',
            'SUPPORTED_OS_PATTERNS': ['(?i)centos.*', '(?i)ubuntu.*'],
            'DEPLOYABLE': True
        }]
        util.load_configs.return_value = configs
        with database.session() as session:
            adapter_api.add_adapters_internal(session)
        adapter.load_adapters()
        self.adapter_object = adapter.list_adapters(user=self.user_object)
        for adapter_obj in self.adapter_object:
            if adapter_obj['name'] == 'openstack_icehouse':
                self.adapter_id = adapter_obj['id']
                break
Пример #3
0
 def setUp(self):
     super(TestModelQuery, self).setUp()
     os.environ['COMPASS_IGNORE_SETTING'] = 'true'
     os.environ['COMPASS_CONFIG_DIR'] = os.path.join(
         os.path.dirname(os.path.abspath(__file__)), 'data')
     reload(setting)
     database.init('sqlite://')
Пример #4
0
    def setUp(self):
        super(AdapterTestCase, self).setUp()
        os.environ['COMPASS_IGNORE_SETTING'] = 'true'
        os.environ['COMPASS_CONFIG_DIR'] = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), 'data')
        reload(setting)
        database.init('sqlite://')
        database.create_db()
        self.user_object = (user_api.get_user_object(
            setting.COMPASS_ADMIN_EMAIL))

        mock_config = mock.Mock(side_effect=self._mock_load_configs)
        self.backup_adapter_configs = util.load_configs
        util.load_configs = mock_config
        adapter.load_adapters(force_reload=True)
        adapter.load_flavors(force_reload=True)
        self.adapter_object = adapter.list_adapters(user=self.user_object)
        self.adapter_obj = None
        self.adapter_id = None
        self.flavor_id = None
        for adapter_obj in self.adapter_object:
            if adapter_obj['name'] == 'openstack_icehouse':
                self.adapter_obj = adapter_obj
                self.adapter_id = adapter_obj['id']
                break

        for flavor in self.adapter_obj['flavors']:
            if flavor['name'] == 'HA-multinodes':
                self.flavor_id = flavor['id']
                break
Пример #5
0
def set_switch_machines():
    """Set switches and machines.

    .. note::
       --switch_machines_file is the filename which stores all switches
       and machines information.
       each line in fake_switches_files presents one machine.
       the format of each line machine,<switch_ip>,<switch_port>,<vlan>,<mac>
       or switch,<switch_ip>,<switch_vendor>,<switch_version>,
       <switch_community>,<switch_state>
    """
    if not flags.OPTIONS.switch_machines_file:
        print 'flag --switch_machines_file is missing'
        return
    database.init()
    switches, switch_machines = util.get_switch_machines_from_file(
        flags.OPTIONS.switch_machines_file)
    user = user_api.get_user_object(
        setting.COMPASS_ADMIN_EMAIL
    )
    switch_mapping = {}
    for switch in switches:
        added_switch = switch_api.add_switch(
            user, False, **switch
        )
        switch_mapping[switch['ip']] = added_switch['id']
    for switch_ip, machines in switch_machines.items():
        if switch_ip not in switch_mapping:
            print 'switch ip %s not found' % switch_ip
            sys.exit(1)
        switch_id = switch_mapping[switch_ip]
        for machine in machines:
            switch_api.add_switch_machine(
                user, switch_id, False, **machine
            )
Пример #6
0
    def setUp(self):
        super(AdapterTestCase, self).setUp()
        os.environ['COMPASS_IGNORE_SETTING'] = 'true'
        os.environ['COMPASS_CONFIG_DIR'] = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            'data'
        )
        reload(setting)
        database.init('sqlite://')
        database.create_db()
        self.user_object = (
            user_api.get_user_object(
                setting.COMPASS_ADMIN_EMAIL
            )
        )

        mock_config = mock.Mock(side_effect=self._mock_load_configs)
        self.backup_adapter_configs = util.load_configs
        util.load_configs = mock_config
        adapter.load_adapters(force_reload=True)
        adapter.load_flavors(force_reload=True)
        self.adapter_object = adapter.list_adapters(user=self.user_object)
        self.adapter_obj = None
        self.adapter_id = None
        self.flavor_id = None
        for adapter_obj in self.adapter_object:
            if adapter_obj['name'] == 'openstack_icehouse':
                self.adapter_obj = adapter_obj
                self.adapter_id = adapter_obj['id']
                break

        for flavor in self.adapter_obj['flavors']:
            if flavor['name'] == 'HA-multinodes':
                self.flavor_id = flavor['id']
                break
Пример #7
0
 def setUp(self):
     super(TestModelFilter, self).setUp()
     os.environ["COMPASS_IGNORE_SETTING"] = "true"
     os.environ["COMPASS_CONFIG_DIR"] = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data")
     reload(setting)
     database.init("sqlite://")
     database.create_db()
Пример #8
0
def set_switch_machines():
    """Set switches and machines.

    .. note::
       --switch_machines_file is the filename which stores all switches
       and machines information.
       each line in fake_switches_files presents one machine.
       the format of each line machine,<switch_ip>,<switch_port>,<vlan>,<mac>
       or switch,<switch_ip>,<switch_vendor>,<switch_version>,
       <switch_community>,<switch_state>
    """
    if not flags.OPTIONS.switch_machines_file:
        print 'flag --switch_machines_file is missing'
        return
    database.init()
    switches, switch_machines = util.get_switch_machines_from_file(
        flags.OPTIONS.switch_machines_file)
    user = user_api.get_user_object(setting.COMPASS_ADMIN_EMAIL)
    switch_mapping = {}
    for switch in switches:
        added_switch = switch_api.add_switch(False, user=user, **switch)
        switch_mapping[switch['ip']] = added_switch['id']
    for switch_ip, machines in switch_machines.items():
        if switch_ip not in switch_mapping:
            print 'switch ip %s not found' % switch_ip
            sys.exit(1)
        switch_id = switch_mapping[switch_ip]
        for machine in machines:
            switch_api.add_switch_machine(switch_id,
                                          False,
                                          user=user,
                                          **machine)
    def setUp(self):
        super(MetadataTestCase, self).setUp()
        reload(setting)
        setting.CONFIG_DIR = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            'data'
        )
        database.init('sqlite://')
        database.create_db()
        adapter.load_adapters()
        metadata.load_metadatas()

        # Get a os_id and adapter_id
        self.user_object = (
            user_api.get_user_object(
                setting.COMPASS_ADMIN_EMAIL
            )
        )
        self.adapter_object = adapter.list_adapters(self.user_object)
        test_adapter = None
        for adapter_obj in self.adapter_object:
            if adapter_obj['name'] == 'openstack_icehouse':
                self.adapter_id = adapter_obj['id']
                test_adapter = adapter_obj
                break
        self.os_id = None
        if test_adapter['flavors']:
            for supported_os in test_adapter['supported_oses']:
                self.os_id = supported_os['os_id']
                break
            for flavor in test_adapter['flavors']:
                if flavor['name'] == 'HA-multinodes':
                    self.flavor_id = flavor['id']
                    break
Пример #10
0
 def setUp(self):
     super(TestModelQuery, self).setUp()
     reload(setting)
     setting.CONFIG_DIR = os.path.join(
         os.path.dirname(os.path.abspath(__file__)),
         'data'
     )
     database.init('sqlite://')
Пример #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)
Пример #12
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()
Пример #13
0
def main():
    """Compass cli entry point."""
    flags.init()
    logsetting.init()
    database.init()
    cli = BootCLI()
    output = cli.run(sys.argv)
    return sys.exit(output)
Пример #14
0
 def setUp(self):
     super(TestGetUserObject, self).setUp()
     reload(setting)
     setting.CONFIG_DIR = os.path.join(
         os.path.dirname(os.path.abspath(__file__)),
         'data'
     )
     database.init('sqlite://')
     database.create_db()
Пример #15
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()
Пример #16
0
def add_subnet():
    if not flags.OPTIONS.subnet:
        print 'flag --subnet is missing'
        return
    database.init()
    subnet_tuple = flags.OPTIONS.subnet
    subnet_name = subnet_tuple[0]
    subnet_cidr = subnet_tuple[1]
    user = user_api.get_user_object(setting.COMPASS_ADMIN_EMAIL)
    network_api.add_subnet(user=user, name=subnet_name, subnet=subnet_cidr)
Пример #17
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()
Пример #18
0
 def setUp(self):
     super(TestGetUserObject, self).setUp()
     os.environ['COMPASS_IGNORE_SETTING'] = 'true'
     os.environ['COMPASS_CONFIG_DIR'] = os.path.join(
         os.path.dirname(os.path.abspath(__file__)),
         'data'
     )
     reload(setting)
     database.init('sqlite://')
     database.create_db()
Пример #19
0
 def setUp(self):
     super(BaseTest, self).setUp()
     os.environ['COMPASS_IGNORE_SETTING'] = 'true'
     os.environ['COMPASS_CONFIG_DIR'] = os.path.join(
         os.path.dirname(os.path.abspath(__file__)), 'data')
     reload(setting)
     database.init('sqlite://')
     database.create_db()
     adapter_api.load_adapters(force_reload=True)
     metadata_api.load_metadatas(force_reload=True)
     adapter_api.load_flavors(force_reload=True)
     self.user_object = (user_api.get_user_object(
         setting.COMPASS_ADMIN_EMAIL))
Пример #20
0
def createdb():
    """Creates database from sqlalchemy models."""
    database.init()
    try:
        database.drop_db()
    except Exception:
        pass

    if setting.DATABASE_TYPE == 'file':
        if os.path.exists(setting.DATABASE_FILE):
            os.remove(setting.DATABASE_FILE)
    database.create_db()
    if setting.DATABASE_TYPE == 'file':
        os.chmod(setting.DATABASE_FILE, 0o777)
Пример #21
0
def createdb():
    """Creates database from sqlalchemy models."""
    database.init()
    try:
        database.drop_db()
    except Exception:
        pass

    if setting.DATABASE_TYPE == 'file':
        if os.path.exists(setting.DATABASE_FILE):
            os.remove(setting.DATABASE_FILE)
    database.create_db()
    if setting.DATABASE_TYPE == 'file':
        os.chmod(setting.DATABASE_FILE, 0o777)
Пример #22
0
 def setUp(self):
     super(BaseTest, self).setUp()
     reload(setting)
     setting.CONFIG_DIR = os.path.join(
         os.path.dirname(os.path.abspath(__file__)),
         'data'
     )
     database.init('sqlite://')
     database.create_db()
     adapter_api.load_adapters()
     metadata_api.load_metadatas()
     self.user_object = (
         user_api.get_user_object(
             setting.COMPASS_ADMIN_EMAIL
         )
     )
Пример #23
0
def set_machine():
    if not flags.OPTIONS.machine_file:
        print 'flag --machine_file is missing'
        return
    database.init()
    machine_file = flags.OPTIONS.machine_file
    user = user_api.get_user_object(setting.COMPASS_ADMIN_EMAIL)
    with open(machine_file) as f:
        machine_data = yaml.load(f)
        for machine in machine_data:
            power_manage = {}
            power_manage.update({"ip": machine.get("power_ip", "")})
            power_manage.update({"username": machine.get("power_user", "")})
            power_manage.update({"password": machine.get("power_pass", "")})
            machine_api.add_machine(user=user,
                                    mac=machine["mac"],
                                    power_type=machine["power_type"],
                                    power_manage=power_manage)
Пример #24
0
 def setUp(self):
     super(BaseTest, self).setUp()
     os.environ['COMPASS_IGNORE_SETTING'] = 'true'
     os.environ['COMPASS_CONFIG_DIR'] = os.path.join(
         os.path.dirname(os.path.abspath(__file__)),
         'data'
     )
     reload(setting)
     database.init('sqlite://')
     database.create_db()
     adapter_api.load_adapters(force_reload=True)
     metadata_api.load_metadatas(force_reload=True)
     adapter_api.load_flavors(force_reload=True)
     self.user_object = (
         user_api.get_user_object(
             setting.COMPASS_ADMIN_EMAIL
         )
     )
Пример #25
0
 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)
Пример #26
0
    def setUp(self):
        super(ApiTestCase, self).setUp()
        reload(setting)
        setting.CONFIG_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data")
        database.init("sqlite://")
        database.create_db()
        adapter_api.load_adapters()
        metadata_api.load_metadatas()

        from compass.api import api as compass_api

        application = compass_api.app
        self.test_client = application.test_client()

        celery.current_app.send_task = mock.Mock()
        from compass.tasks import client as celery_client

        celery_client.celery.send_task = mock.Mock()
        url = "/users/token"
        data = self.USER_CREDENTIALS
        request_data = json.dumps(data)
        return_value = self.test_client.post(url, data=request_data)
        resp = return_value.get_data()
        resp = json.loads(resp)
        self.token = resp["token"]

        # create a cluster
        adapter_name, adapter_id, os_id, flavor_id = self._get_adapter_info()
        url = "/clusters"
        data = {}
        data["name"] = "test_cluster1"
        data["adapter_id"] = adapter_id
        data["os_id"] = os_id
        self.os_id = os_id
        data["flavor_id"] = flavor_id
        self.post(url, data)
        data = {}
        data["name"] = "test_cluster2"
        data["adapter_id"] = adapter_id
        data["os_id"] = os_id
        self.flavor_id = flavor_id
        data["flavor_id"] = flavor_id
        self.post(url, data)

        # create a switch
        url = "/switches"
        datas = [
            {
                "ip": self.SWITCH_IP_ADDRESS,
                "credentials": {"version": "2c", "community": "public"},
                "vendor": "huawei",
                "state": "under_monitoring",
            },
            {
                "ip": "172.29.8.40",
                "credentials": {"version": "2c", "community": "public"},
                "vendor": "huawei",
                "state": "under_monitoring",
            },
        ]
        for data in datas:
            self.post(url, data)
Пример #27
0
def dropdb():
    """Drops database from sqlalchemy models."""
    database.init()
    database.drop_db()
Пример #28
0
        try:
            pool = Pool(processes=flags.OPTIONS.thread_pool_size)
            for switch_ip, switch_credentials in poll_switches.items():
                pool.apply_async(
                    poll_switch.poll_switch,
                    (user.email, switch_ip, switch_credentials)
                )
            pool.close()
            pool.join()
        except Exception as error:
            logging.error('failed to poll switches %s',
                          poll_switches)
            logging.exception(error)


if __name__ == '__main__':
    flags.init()
    logsetting.init()
    database.init()
    logging.info('run poll_switch')
    daemonize.daemonize(
        functools.partial(
            pollswitches,
            [switch_ip
             for switch_ip in flags.OPTIONS.switch_ips.split(',')
             if switch_ip]),
        flags.OPTIONS.run_interval,
        pidfile=lockfile.FileLock('/var/run/poll_switch.pid'),
        stderr=open('/tmp/poll_switch_err.log', 'w+'),
        stdout=open('/tmp/poll_switch_out.log', 'w+'))
Пример #29
0
    def setUp(self):
        super(ApiTestCase, self).setUp()
        database.init(self.DATABASE_URL)
        database.create_db()

        self.test_client = app.test_client()
Пример #30
0
def dropdb():
    """Drops database from sqlalchemy models."""
    database.init()
    database.drop_db()
Пример #31
0
                filtered_package_installers.items()):
            celery.send_task(
                'compass.tasks.clean_package_installer',
                (package_installer['name'], package_installer['settings']))
    else:
        for os_installer_name, os_installer in (
                filtered_os_installers.items()):
            try:
                clean.clean_os_installer(os_installer['name'],
                                         os_installer['settings'])
            except Exception as error:
                logging.error('failed to clean os installer %s',
                              os_installer_name)
                logging.exception(error)
        for package_installer_name, package_installer in (
                filtered_package_installers.items()):
            try:
                clean.clean_package_installer(package_installer['name'],
                                              package_installer['settings'])
            except Exception as error:
                logging.error('failed to clean package installer %s',
                              package_installer_name)
                logging.exception(error)


if __name__ == '__main__':
    flags.init()
    logsetting.init()
    database.init()
    clean_installers()
Пример #32
0
    def setUp(self):
        super(ApiTestCase, self).setUp()
        os.environ['COMPASS_IGNORE_SETTING'] = 'true'
        os.environ['COMPASS_CONFIG_DIR'] = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), 'data')
        reload(setting)
        database.init('sqlite://')
        database.create_db()
        adapter_api.load_adapters(force_reload=True)
        metadata_api.load_metadatas(force_reload=True)
        adapter_api.load_flavors(force_reload=True)

        from compass.api import api as compass_api
        application = compass_api.app
        self.test_client = application.test_client()

        celery.current_app.send_task = mock.Mock()
        from compass.tasks import client as celery_client
        celery_client.celery.send_task = mock.Mock()
        url = '/users/token'
        data = self.USER_CREDENTIALS
        request_data = json.dumps(data)
        return_value = self.test_client.post(
            url,
            data=request_data,
        )
        resp = return_value.get_data()
        resp = json.loads(resp)
        self.token = resp['token']

        # create a cluster
        adapter_name, adapter_id, os_id, flavor_id = (self._get_adapter_info())
        url = '/clusters'
        data = {}
        data['name'] = 'test_cluster1'
        data['adapter_id'] = adapter_id
        data['os_id'] = os_id
        self.os_id = os_id
        data['flavor_id'] = flavor_id
        self.post(url, data)
        data = {}
        data['name'] = 'test_cluster2'
        data['adapter_id'] = adapter_id
        data['os_id'] = os_id
        self.flavor_id = flavor_id
        data['flavor_id'] = flavor_id
        self.post(url, data)

        # create a switch
        url = '/switches'
        datas = [{
            'ip': self.SWITCH_IP_ADDRESS,
            'credentials': {
                "version": "2c",
                "community": "public"
            },
            'vendor': 'huawei',
            'state': 'under_monitoring'
        }, {
            'ip': '172.29.8.40',
            'credentials': {
                "version": "2c",
                "community": "public"
            },
            'vendor': 'huawei',
            'state': 'under_monitoring'
        }]
        for data in datas:
            self.post(url, data)
Пример #33
0
    def setUp(self):
        super(HostTestCase, self).setUp()
        os.environ['COMPASS_IGNORE_SETTING'] = 'true'
        os.environ['COMPASS_CONFIG_DIR'] = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            'data'
        )
        reload(setting)
        database.init('sqlite://')
        database.create_db()
        adapter.load_adapters(force_reload=True)
        metadata.load_metadatas(force_reload=True)
        adapter.load_flavors(force_reload=True)

        self.user_object = (
            user_api.get_user_object(
                setting.COMPASS_ADMIN_EMAIL
            )
        )
        # get adapter information
        list_adapters = adapter.list_adapters(user=self.user_object)
        for list_adapter in list_adapters:
            for supported_os in list_adapter['supported_oses']:
                self.os_id = supported_os['os_id']
                break
            if list_adapter['flavors']:
                details = list_adapter['flavors']
                for detail in details:
                    if detail['display_name'] == 'allinone':
                        roles = detail['roles']
                        for role in roles:
                            self.adapter_id = role['adapter_id']
                            self.flavor_id = role['flavor_id']
                            break

        # add cluster
        cluster_names = ['test_cluster1', 'test_cluster2']
        for cluster_name in cluster_names:
            cluster.add_cluster(
                user=self.user_object,
                adapter_id=self.adapter_id,
                os_id=self.os_id,
                flavor_id=self.flavor_id,
                name=cluster_name
            )
        clusters = cluster.list_clusters(user=self.user_object)
        self.roles = None
        for list_cluster in clusters:
            for item in list_cluster['flavor']['roles']:
                self.roles = item
            if list_cluster['name'] == 'test_cluster1':
                self.cluster_id = list_cluster['id']
                break
        # add switch
        switch.add_switch(
            user=self.user_object,
            ip='172.29.8.40'
        )
        switches = switch.list_switches(user=self.user_object)
        self.switch_id = None
        for item in switches:
            self.switch_id = item['id']
        macs = ['28:6e:d4:46:c4:25', '00:0c:29:bf:eb:1d']
        for mac in macs:
            switch.add_switch_machine(
                self.switch_id,
                user=self.user_object,
                mac=mac,
                port='1'
            )
        # get machine information
        machines = machine.list_machines(user=self.user_object)
        self.machine_ids = []
        for item in machines:
            self.machine_ids.append(item['id'])
        # add cluster host
        name = ['newname1', 'newname2']
        for i in range(0, 2):
            cluster.add_cluster_host(
                self.cluster_id,
                user=self.user_object,
                machine_id=self.machine_ids[i],
                name=name[i]
            )
        self.host_ids = []
        clusterhosts = cluster.list_clusterhosts(user=self.user_object)
        for clusterhost in clusterhosts:
            self.host_ids.append(clusterhost['host_id'])
        # add subnet
        subnets = ['10.145.88.0/23', '192.168.100.0/23']
        for subnet in subnets:
            network.add_subnet(
                user=self.user_object,
                subnet=subnet
            )
        list_subnet = network.list_subnets(
            user=self.user_object
        )
        self.subnet_ids = []
        for item in list_subnet:
            self.subnet_ids.append(item['id'])
        # add host network
        host.add_host_network(
            self.host_ids[0],
            user=self.user_object,
            interface='eth0',
            ip='10.145.88.0',
            subnet_id=self.subnet_ids[0],
            is_mgmt=True
        )
        host.add_host_network(
            self.host_ids[1],
            user=self.user_object,
            interface='eth1',
            ip='192.168.100.0',
            subnet_id=self.subnet_ids[1],
            is_promiscuous=True
        )
        # add log history
        filenames = ['log1', 'log2']
        for filename in filenames:
            host.add_host_log_history(
                self.host_ids[0],
                user=self.user_object,
                filename=filename
            )

        self.os_configs = {
            'general': {
                'language': 'EN',
                'timezone': 'UTC',
                'http_proxy': 'http://127.0.0.1:3128',
                'https_proxy': 'http://127.0.0.1:3128',
                'no_proxy': [
                    '127.0.0.1',
                    'compass'
                ],
                'ntp_server': '127.0.0.1',
                'dns_servers': [
                    '127.0.0.1'
                ],
                'domain': 'ods.com',
                'search_path': [
                    'ods.com'
                ],
                'default_gateway': '127.0.0.1',
            },
            'server_credentials': {
                'username': '******',
                'password': '******',
            },
            'partition': {
                '/var': {
                    'max_size': '100G',
                    'percentage': 10,
                    'size': '1G'
                }
            }
        }
        self.package_configs = {
            'security': {
                'service_credentials': {
                    '$service': {
                        'username': '******',
                        'password': '******'
                    }
                },
                'console_credentials': {
                    '$console': {
                        'username': '******',
                        'password': '******'
                    }
                }
            },
            'network_mapping': {
                '$interface_type': 'eth0'
            }
        }
Пример #34
0
    def setUp(self):
        super(ApiTestCase, self).setUp()
        os.environ['COMPASS_IGNORE_SETTING'] = 'true'
        os.environ['COMPASS_CONFIG_DIR'] = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            'data'
        )
        reload(setting)
        database.init('sqlite://')
        database.create_db()
        adapter_api.load_adapters(force_reload=True)
        metadata_api.load_metadatas(force_reload=True)
        adapter_api.load_flavors(force_reload=True)

        from compass.api import api as compass_api
        application = compass_api.app
        self.test_client = application.test_client()

        celery.current_app.send_task = mock.Mock()
        from compass.tasks import client as celery_client
        celery_client.celery.send_task = mock.Mock()
        url = '/users/token'
        data = self.USER_CREDENTIALS
        request_data = json.dumps(data)
        return_value = self.test_client.post(
            url,
            data=request_data,
        )
        resp = return_value.get_data()
        resp = json.loads(resp)
        self.token = resp['token']

        # create a cluster
        adapter_name, adapter_id, os_id, flavor_id = (
            self._get_adapter_info()
        )
        url = '/clusters'
        data = {}
        data['name'] = 'test_cluster1'
        data['adapter_id'] = adapter_id
        data['os_id'] = os_id
        self.os_id = os_id
        data['flavor_id'] = flavor_id
        self.post(url, data)
        data = {}
        data['name'] = 'test_cluster2'
        data['adapter_id'] = adapter_id
        data['os_id'] = os_id
        self.flavor_id = flavor_id
        data['flavor_id'] = flavor_id
        self.post(url, data)

        # create a switch
        url = '/switches'
        datas = [
            {
                'ip': self.SWITCH_IP_ADDRESS,
                'credentials': {
                    "version": "2c",
                    "community": "public"
                },
                'vendor': 'huawei',
                'state': 'under_monitoring'
            },
            {
                'ip': '172.29.8.40',
                'credentials': {
                    "version": "2c",
                    "community": "public"
                },
                'vendor': 'huawei',
                'state': 'under_monitoring'
            }
        ]
        for data in datas:
            self.post(url, data)