Exemplo n.º 1
0
    def _replace_neutron_l2_proxy_json(self, host_info):
        """
        TODO: to get host ip of proxies, and scp config file of json to these proxies.
        :return:
        """
        log.info('Start to replace neutron l2 proxy json in proxy nodes..')
        print('Start to replace neutron l2 proxy json..')
        for proxy in self.proxies:
            neutron_network_role = self._get_neutron_role_name(proxy)
            for host in host_info['hosts']:
                roles_list = host['roles']
                local_path_of_neutron_l2_proxy = os.path.join(
                    utils.get_patches_tool_path(),
                    CfgFilePath.NEUTRON_L2_PROXY_PATH_TEMPLATE)
                if neutron_network_role in roles_list:
                    proxy_host_ip = host['manageip']
                    log.info(
                        'Start remote copy neutron l2 proxy json to host: %s' %
                        proxy_host_ip)
                    try:
                        utils.remote_open_root_permit_for_host(proxy_host_ip)
                        ssh = SSHConnection(proxy_host_ip, SysUserInfo.ROOT,
                                            SysUserInfo.ROOT_PWD)
                        ssh.put(local_path_of_neutron_l2_proxy,
                                CfgFilePath.NEUTRON_L2_PROXY_PATH)
                        ssh.close()
                    except Exception, e:
                        log.error(
                            'Exception when remote copy neutron l2 proxy json to host: %s'
                            % proxy_host_ip)
                        log.error('Exception: %s' % traceback.format_exc())

                    log.info(
                        'Finish remote copy neutron l2 proxy json to host: %s'
                        % proxy_host_ip)
Exemplo n.º 2
0
    def install(self):
        result = 'FAILED'
        patch_files = self.get_patch_files(self.patch_path, self.filters)
        if not patch_files:
            logger.error('No files in %s' % self.patch_path)
        for absolute_path, relative_path in patch_files:
            # installed_path is full install path,
            # for example: /usr/lib/python2.7/dist-packages/nova/conductor/manager.py
            openstack_installed_file = os.path.join(self.openstack_install_path, relative_path)
            # self.bak_patched_file(openstack_installed_file, relative_path)

            copy_dir = os.path.dirname(openstack_installed_file)

            ssh = SSHConnection(self.host_ip, 'root', 'Huawei@CLOUD8!')
            # cp_result = CommonCMD.cp_to(absolute_path, openstack_installed_file)
            try:
                if not stat.S_ISDIR(ssh.get_sftp().stat(copy_dir).st_mode):
                    log.info('create dir: %s' % copy_dir)
                    ssh.get_sftp().mkdir(copy_dir)
                ssh.put(absolute_path, openstack_installed_file)
            except IOError, e:
                if e.args[1] == 'No such file':
                    log.info('There is no such dir in host: %s, create dir: %s' % (self.host_ip, copy_dir))
                    ssh.get_sftp().mkdir(copy_dir)
                else:
                     error_message = 'Exception occure when copy file<%s>, Exception.args: %s' \
                                % (openstack_installed_file, e.args)
                     log.error(error_message)
                     print(error_message)
            except Exception, e:
                error_message = 'Exception occure when copy file<%s>, Exception.args: %s' \
                                % (openstack_installed_file, e.args)
                log.error(error_message)
                print(error_message)
Exemplo n.º 3
0
    def install(self):
        result = 'FAILED'
        patch_files = self.get_patch_files(self.patch_path, self.filters)
        if not patch_files:
            logger.error('No files in %s' % self.patch_path)
        for absolute_path, relative_path in patch_files:
            # installed_path is full install path,
            openstack_installed_file = os.path.join(self.openstack_install_path, relative_path)

            copy_dir = os.path.dirname(openstack_installed_file)

            ssh = SSHConnection(self.host_ip, 'root', 'Huawei@CLOUD8!')
            try:
                if not stat.S_ISDIR(ssh.get_sftp().stat(copy_dir).st_mode):
                    log.info('create dir: %s' % copy_dir)
                    ssh.get_sftp().mkdir(copy_dir)
                ssh.put(absolute_path, openstack_installed_file)
            except IOError, e:
                if e.args[1] == 'No such file':
                    log.info('There is no such dir in host: %s, create dir: %s' % (self.host_ip, copy_dir))
                    cmd = "mkdir -p %s" % copy_dir
                    utils.remote_execute_cmd(host_ip=self.host_ip, user="******", passwd="Huawei@CLOUD8!", cmd=cmd)
                else:
                     error_message = 'Exception occure when copy file<%s>, Exception.args: %s' \
                                % (openstack_installed_file, e.args)
                     log.error(error_message)
                     print(error_message)
            except Exception, e:
                error_message = 'Exception occure when copy file<%s>, Exception.args: %s' \
                                % (openstack_installed_file, e.args)
                log.error(error_message)
                print(error_message)
Exemplo n.º 4
0
    def _replace_neutron_l2_proxy_json(self, host_info):
        """
        TODO: to get host ip of proxies, and scp config file of json to these proxies.
        :return:
        """

        log.info('Start to replace neutron l2 proxy json in proxy nodes. self.proxies = %s' % self.proxies)
        log.info('Start to replace neutron l2 proxy json in proxy nodes. host_info = %s' % host_info)

        for proxy in self.proxies:
            log.info('Start to replace neutron l2 proxy json in proxy nodes. proxy = %s' % proxy)
            neutron_network_role = self._get_neutron_role_name(proxy)
            for host in host_info['hosts']:

                roles_list = host['roles']
                local_path_of_neutron_l2_proxy = os.path.join(
                    utils.get_patches_tool_path(), CfgFilePath.NEUTRON_L2_PROXY_PATH_TEMPLATE)
                if neutron_network_role in roles_list:
                    proxy_host_ip = host['manageip']
                    log.info('Start remote copy neutron l2 proxy json to host: %s' % proxy_host_ip)
                    try:
                        # utils.remote_open_root_permit_for_host(proxy_host_ip)
                        ssh = SSHConnection(proxy_host_ip, SysUserInfo.ROOT, SysUserInfo.ROOT_PWD)
                        ssh.put(local_path_of_neutron_l2_proxy, CfgFilePath.NEUTRON_L2_PROXY_PATH)
                        ssh.close()
                        log.info('Finish remote copy neutron l2 proxy json to host: %s' % proxy_host_ip)
                    except Exception, e:
                        log.error('Exception when remote copy neutron l2 proxy json to host: %s' % proxy_host_ip)
                        log.error('Exception: %s' % traceback.format_exc())
                    finally:
                        break
Exemplo n.º 5
0
    def config_big_l2_layer_in_proxy_node(self):
        host_list = None
        for i in range(3):
            try:
                host_list = RefCPSService.host_list()
                log.info("get host list success.")
                break
            except Exception as e:
                log.error("get host list error, try again. error: %s" % e.message)
                time.sleep(1)
                continue

        if host_list is None:
            log.error("config big l2 layer for proxies failed, get host list failed.")
            return False

        for proxy in self.proxies:
            # enable l2 remote port
            self.__enable_l2_remote_port_for_proxy__(proxy)

            # copy file
            host_id = self.proxy_match_host[proxy]
            host_ip = None
            for host in host_list["hosts"]:
                if host_id == host["id"]:
                    host_ip = host["manageip"]
                    break

            if host_ip is None:
                log.error("proxy not exist, proxy: %s, proxy id: %s" % (proxy, host_id))
                continue

            log.info('start to replace neutron l2 proxy json in proxy nodes. proxy: %s' % proxy)
            replace_result = False
            for i in range(3):
                try:
                    # utils.remote_open_root_permit_for_host(proxy_host_ip)
                    local_path_of_neutron_l2_proxy = os.path.join(
                        utils.get_patches_tool_path(),
                        CfgFilePath.NEUTRON_L2_PROXY_PATH_TEMPLATE)
                    ssh = SSHConnection(host_ip, SysUserInfo.ROOT, SysUserInfo.ROOT_PWD)
                    ssh.put(local_path_of_neutron_l2_proxy, CfgFilePath.NEUTRON_L2_PROXY_PATH)
                    ssh.close()
                    replace_result = True
                    log.info('replace neutron l2 proxy json success, proxy: %s' % proxy)
                    break
                except Exception, e:
                    log.error('replace neutron l2 proxy json error, try again, proxy: %s, error: %s' % (proxy, e.message))
                    time.sleep(1)
                    continue
                finally:
                    ssh.close()
Exemplo n.º 6
0
    def install(self):
        result = 'FAILED'
        patch_files = self.get_patch_files(self.patch_path, self.filters)
        if not patch_files:
            logger.error('No files in %s' % self.patch_path)
        for absolute_path, relative_path in patch_files:
            # installed_path is full install path,
            openstack_installed_file = os.path.join(
                self.openstack_install_path, relative_path)

            copy_dir = os.path.dirname(openstack_installed_file)

            ssh = SSHConnection(self.host_ip, 'root', 'Huawei@CLOUD8!')
            try:
                if not stat.S_ISDIR(ssh.get_sftp().stat(copy_dir).st_mode):
                    log.info('create dir: %s' % copy_dir)
                    ssh.get_sftp().mkdir(copy_dir)
                ssh.put(absolute_path, openstack_installed_file)
            except IOError, e:
                if e.args[1] == 'No such file':
                    log.info(
                        'There is no such dir in host: %s, create dir: %s' %
                        (self.host_ip, copy_dir))
                    cmd = "mkdir -p %s" % copy_dir
                    utils.remote_execute_cmd(host_ip=self.host_ip,
                                             user="******",
                                             passwd="Huawei@CLOUD8!",
                                             cmd=cmd)
                else:
                    error_message = 'Exception occure when copy file<%s>, Exception.args: %s' \
                               % (openstack_installed_file, e.args)
                    log.error(error_message)
                    print(error_message)
            except Exception, e:
                error_message = 'Exception occure when copy file<%s>, Exception.args: %s' \
                                % (openstack_installed_file, e.args)
                log.error(error_message)
                print(error_message)
Exemplo n.º 7
0
    def install(self):
        result = 'FAILED'
        patch_files = self.get_patch_files(self.patch_path, self.filters)
        if not patch_files:
            logger.error('No files in %s' % self.patch_path)
        for absolute_path, relative_path in patch_files:
            # installed_path is full install path,
            # for example: /usr/lib/python2.7/dist-packages/nova/conductor/manager.py
            openstack_installed_file = os.path.join(
                self.openstack_install_path, relative_path)
            # self.bak_patched_file(openstack_installed_file, relative_path)

            copy_dir = os.path.dirname(openstack_installed_file)

            ssh = SSHConnection(self.host_ip, 'root', 'Huawei@CLOUD8!')
            # cp_result = CommonCMD.cp_to(absolute_path, openstack_installed_file)
            try:
                if not stat.S_ISDIR(ssh.get_sftp().stat(copy_dir).st_mode):
                    log.info('create dir: %s' % copy_dir)
                    ssh.get_sftp().mkdir(copy_dir)
                ssh.put(absolute_path, openstack_installed_file)
            except IOError, e:
                if e.args[1] == 'No such file':
                    log.info(
                        'There is no such dir in host: %s, create dir: %s' %
                        (self.host_ip, copy_dir))
                    ssh.get_sftp().mkdir(copy_dir)
                else:
                    error_message = 'Exception occure when copy file<%s>, Exception.args: %s' \
                               % (openstack_installed_file, e.args)
                    log.error(error_message)
                    print(error_message)
            except Exception, e:
                error_message = 'Exception occure when copy file<%s>, Exception.args: %s' \
                                % (openstack_installed_file, e.args)
                log.error(error_message)
                print(error_message)
Exemplo n.º 8
0
    def config_big_l2_layer_in_proxy_node(self):
        host_list = None
        for i in range(3):
            try:
                host_list = RefCPSService.host_list()
                log.info("get host list success.")
                break
            except Exception as e:
                log.error("get host list error, try again. error: %s" %
                          e.message)
                time.sleep(1)
                continue

        if host_list is None:
            log.error(
                "config big l2 layer for proxies failed, get host list failed."
            )
            return False

        for proxy in self.proxies:
            # enable l2 remote port
            self.__enable_l2_remote_port_for_proxy__(proxy)

            # copy file
            host_id = self.proxy_match_host[proxy]
            host_ip = None
            for host in host_list["hosts"]:
                if host_id == host["id"]:
                    host_ip = host["manageip"]
                    break

            if host_ip is None:
                log.error("proxy not exist, proxy: %s, proxy id: %s" %
                          (proxy, host_id))
                continue

            log.info(
                'start to replace neutron l2 proxy json in proxy nodes. proxy: %s'
                % proxy)
            replace_result = False
            for i in range(3):
                try:
                    # utils.remote_open_root_permit_for_host(proxy_host_ip)
                    local_path_of_neutron_l2_proxy = os.path.join(
                        utils.get_patches_tool_path(),
                        CfgFilePath.NEUTRON_L2_PROXY_PATH_TEMPLATE)
                    ssh = SSHConnection(host_ip, SysUserInfo.ROOT,
                                        SysUserInfo.ROOT_PWD)
                    ssh.put(local_path_of_neutron_l2_proxy,
                            CfgFilePath.NEUTRON_L2_PROXY_PATH)
                    ssh.close()
                    replace_result = True
                    log.info(
                        'replace neutron l2 proxy json success, proxy: %s' %
                        proxy)
                    break
                except Exception, e:
                    log.error(
                        'replace neutron l2 proxy json error, try again, proxy: %s, error: %s'
                        % (proxy, e.message))
                    time.sleep(1)
                    continue
                finally:
                    ssh.close()