Ejemplo n.º 1
0
    def start_node(self):
        try:
            super(HostNode, self).start_node()
            self.stop_node()
            ansible_dir = os.path.dirname(NODE_ANSIBLE_YAML)
            ansible.execute_ansible(self.node_ip, self.node_username, \
                    self.NODE_PASSWORD, ansible_dir, self.ansible_cmd)

            start_node_cmd = 'export CATALINA_OPTS=" -Djava.net.preferIPv4Stack=true "; sh ' + self.start_script
            if self.NODE_PASSWORD:
                start_node_cmd = 'export ZSTACK_MANAGEMENT_SERVER_PASSWORD=%s; %s'\
                        % (self.NODE_PASSWORD, start_node_cmd)
            self._rshell(start_node_cmd)
        except Exception as e:
            node_exception.append(sys.exc_info())
 def start_node(self):
     try:
         super(HostNode, self).start_node()
         self.stop_node()
         ansible_dir = os.path.dirname(NODE_ANSIBLE_YAML)
         ansible.execute_ansible(self.node_ip, self.node_username, \
                 self.NODE_PASSWORD, ansible_dir, self.ansible_cmd)
 
         start_node_cmd = 'export CATALINA_OPTS=" -Djava.net.preferIPv4Stack=true "; sh ' + self.start_script
         if self.NODE_PASSWORD:
             start_node_cmd = 'export ZSTACK_MANAGEMENT_SERVER_PASSWORD=%s; %s'\
                     % (self.NODE_PASSWORD, start_node_cmd)
         self._rshell(start_node_cmd)
     except Exception as e:
         node_exception.append(sys.exc_info())
Ejemplo n.º 3
0
    def deploy_test_agent(self, target=None):
        print('Deploy test agent\n')
        if not self.test_agent_path:
            print('Not find test_agent. Stop deploying test agent.\n')
            return

        testagentdir = None
        try:

            def untar_test_agent():
                tmpdir = tempfile.mkdtemp()
                shell.call('tar jxf %s -C %s' % (self.test_agent_path, tmpdir))
                shell.call('cd %s/zstacktestagent/; tar jcf pypi.tar.bz pypi' \
                        % tmpdir)
                return '%s/zstacktestagent' % tmpdir

            def _wait_echo(target_ip):
                try:
                    rspstr = http.json_dump_post(
                        testagent.build_http_path(target_ip,
                                                  host_plugin.ECHO_PATH))
                except:
                    print(
                        'zstack-testagent does not startup, will try again ...'
                    )
                    return False
                return True

            def find_zstacklib(search_path):
                match = glob.glob(
                    os.path.join(search_path, 'zstacklib-*.tar.gz'))
                try:
                    return os.path.basename(match[0])
                except:
                    return 'zstacklib-1.6.tar.gz'

            testagentdir = untar_test_agent()
            pkg_zstacklib = find_zstacklib(testagentdir)
            ansible.check_and_install_ansible()

            lib_files = ['testagent/zstacktestagent-1.0.0.tar.gz', \
                    'testagent/%s' % (pkg_zstacklib) ]

            if not target:
                #default will deploy all test hosts.
                exc_info = []
                for h in self.test_agent_hosts:
                    print('Deploy test agent in host: [%s] \n' %
                          h.managementIp_)
                    if h.username_ != 'root':
                        ansible_become_args = "ansible_become=yes become_user=root ansible_become_pass=%s" % (
                            h.password_)
                    else:
                        ansible_become_args = ""

                    if hasattr(h, 'port_'):
                        ansible_port_args = "ansible_ssh_port=%s" % (h.port_)
                    else:
                        ansible_port_args = ""

                    ansible_cmd_args = "host=%s \
                            ansible_ssh_user=%s \
                            ansible_ssh_pass=%s \
                            %s \
                            %s \
                            pkg_testagent=zstacktestagent-1.0.0.tar.gz \
                            pkg_zstacklib=%s \
                            pypi_source_tar=pypi.tar.bz"                                                         % \
                            (h.managementIp_, h.username_, h.password_, ansible_become_args, ansible_port_args, pkg_zstacklib)

                    if ENV_HTTP_PROXY:
                        ansible_cmd_args = "%s http_proxy=%s https_proxy=%s" % \
                            (ansible_cmd_args, ENV_HTTP_PROXY, ENV_HTTPS_PROXY)

                    ansible_cmd = "testagent.yaml -e '%s'" % ansible_cmd_args

                    if hasattr(h, 'port_'):
                        thread = threading.Thread(target=ansible.execute_ansible,\
                            args=(h.managementIp_, h.username_, h.password_,\
                            testagentdir, ansible_cmd, lib_files, exc_info, h.port_))
                    else:
                        thread = threading.Thread(target=ansible.execute_ansible,\
                            args=(h.managementIp_, h.username_, h.password_,\
                            testagentdir, ansible_cmd, lib_files, exc_info))

                    # Wrap up old zstack logs in /var/log/zstack/
                    #print('archive test log on host: [%s] \n' % h.managementIp_)
                    #try:
                    #    if hasattr(h, 'port_'):
                    #        log.cleanup_log(h.managementIp_, h.username_, h.password_, h.port_)
                    #    else:
                    #        log.cleanup_log(h.managementIp_, h.username_, h.password_)
                    #except Exception as e:
                    #    print "clean up old testing logs meet execption on management node: %s" % h.managementIp_
                    #    raise e

                    thread.start()
                #if localhost is not in hosts, should do log archive for zstack
                log.cleanup_local_log()

                self._wait_for_thread_completion('install test agent', 200)

                for h in self.test_agent_hosts:
                    if not linux.wait_callback_success(
                            _wait_echo, h.managementIp_, 5, 0.2, True):
                        raise ActionError(
                            'testagent is not start up in 5s on %s, after it is deployed by ansible.'
                            % h.managementIp_)

            else:
                print('Deploy test agent in host: %s \n' % target.managementIp)
                ansible_cmd_args = "host=%s \
                        pkg_testagent=zstacktestagent-1.0.0.tar.gz \
                        pkg_zstacklib=%s \
                        pypi_source_tar=pypi.tar.bz"                                                     % \
                        (target.managementIp, pkg_zstacklib)
                if ENV_HTTP_PROXY:
                    ansible_cmd_args = "%s http_proxy=%s https_proxy=%s" % \
                        (ansible_cmd_args, ENV_HTTP_PROXY, ENV_HTTPS_PROXY)

                ansible_cmd = "testagent.yaml -e '%s'" % ansible_cmd_args
                ansible.execute_ansible(target.managementIp, target.username, \
                        target.password, testagentdir, ansible_cmd, lib_files)
                if not linux.wait_callback_success(
                        _wait_echo, target.managementIp, 5, 0.2):
                    raise ActionError(
                        'testagent is not start up in 5s on %s, after it is deployed by ansible.'
                        % target.managementIp)

        finally:
            if testagentdir:
                shell.call('rm -rf %s' % testagentdir)
Ejemplo n.º 4
0
    def deploy_test_agent(self, target=None):
        print('Deploy test agent\n')
        if not self.test_agent_path:
            print('Not find test_agent. Stop deploying test agent.\n')
            return

        testagentdir = None
        try:

            def untar_test_agent():
                tmpdir = tempfile.mkdtemp()
                shell.call('tar xzf %s -C %s' % (self.test_agent_path, tmpdir))
                return '%s/zstacktestagent' % tmpdir

            def _wait_echo(target_ip):
                try:
                    rspstr = http.json_dump_post(
                        testagent.build_http_path(target_ip,
                                                  host_plugin.ECHO_PATH))
                except:
                    print(
                        'zstack-testagent does not startup, will try again ...'
                    )
                    return False
                return True

            testagentdir = untar_test_agent()
            ansible.check_and_install_ansible()

            lib_files = ['testagent/zstacktestagent-0.1.0.tar.gz', \
                    'testagent/zstacklib-0.1.0.tar.gz' ]

            if not target:
                #default will deploy all test hosts.
                exc_info = []
                for h in self.test_agent_hosts:
                    print('Deploy test agent in host: [%s] \n' %
                          h.managementIp_)
                    ansible_cmd_args = "host=%s \
                            pkg_testagent=zstacktestagent-0.1.0.tar.gz \
                            pkg_zstacklib=zstacklib-0.6.tar.gz \
                            pypi_url=%s"                                         % \
                            (h.managementIp_, ENV_PYPI_URL)
                    if ENV_HTTP_PROXY:
                        ansible_cmd_args = "%s http_proxy=%s https_proxy=%s" % \
                            (ansible_cmd_args, ENV_HTTP_PROXY, ENV_HTTPS_PROXY)

                    ansible_cmd = "testagent.yaml -e '%s'" % ansible_cmd_args

                    thread = threading.Thread(target=ansible.execute_ansible,\
                        args=(h.managementIp_, h.username_, h.password_,\
                        testagentdir, ansible_cmd, lib_files, exc_info))

                    # Wrap up old zstack logs in /var/log/zstack/
                    print('archive test log on host: [%s] \n' %
                          h.managementIp_)
                    try:
                        log.cleanup_log(h.managementIp_, h.username_,
                                        h.password_)
                    except Exception as e:
                        print "clean up old testing logs meet execption on management node: %s" % h.managementIp_
                        raise e

                    thread.start()
                #if localhost is not in hosts, should do log archive for zstack
                log.cleanup_local_log()

                self._wait_for_thread_completion('install test agent', 200)

                for h in self.test_agent_hosts:
                    if not linux.wait_callback_success(
                            _wait_echo, h.managementIp_, 5, 0.2, True):
                        raise ActionError(
                            'testagent is not start up in 5s on %s, after it is deployed by ansible.'
                            % h.managementIp_)

            else:
                print('Deploy test agent in host: %s \n' % target.managementIp)
                ansible_cmd_args = "host=%s \
                        pkg_testagent=zstacktestagent-0.1.0.tar.gz \
                        pkg_zstacklib=zstacklib-0.6.tar.gz \
                        pypi_url=%s"                                     % \
                        (target.managementIp, ENV_PYPI_URL)
                if ENV_HTTP_PROXY:
                    ansible_cmd_args = "%s http_proxy=%s https_proxy=%s" % \
                        (ansible_cmd_args, ENV_HTTP_PROXY, ENV_HTTPS_PROXY)

                ansible_cmd = "testagent.yaml -e '%s'" % ansible_cmd_args
                ansible.execute_ansible(target.managementIp, target.username, \
                        target.password, testagentdir, ansible_cmd, lib_files)
                if not linux.wait_callback_success(
                        _wait_echo, target.managementIp, 5, 0.2):
                    raise ActionError(
                        'testagent is not start up in 5s on %s, after it is deployed by ansible.'
                        % target.managementIp)

        finally:
            if testagentdir:
                shell.call('rm -rf %s' % testagentdir)
Ejemplo n.º 5
0
    def deploy_test_agent(self, target=None):
        print('Deploy test agent\n')
        if not self.test_agent_path:
            print('Not find test_agent. Stop deploying test agent.\n')
            return

        testagentdir = None

        def _wait_echo(target_ip):
            try:
                rspstr = http.json_dump_post(
                    testagent.build_http_path(target_ip,
                                              host_plugin.ECHO_PATH))
            except:
                print('zstack-testagent does not startup, will try again ...')
                return False
            return True

        testagentdir = self.test_agent_path
        ansible.check_and_install_ansible()

        lib_files = []

        if not target:
            #default will deploy all test hosts.
            exc_info = []
            for h in self.test_agent_hosts:
                print('Deploy test agent in host: [%s] \n' % h.managementIp_)
                if h.username_ != 'root':
                    ansible_become_args = "ansible_become=yes become_user=root ansible_become_pass=%s" % (
                        h.password_)
                else:
                    ansible_become_args = ""

                if hasattr(h, 'port_'):
                    ansible_port_args = "ansible_ssh_port=%s" % (h.port_)
                else:
                    ansible_port_args = ""

                ansible_cmd_args = "host=%s \
                        ansible_ssh_user=%s \
                        ansible_ssh_pass=%s \
                        %s \
                        %s \
                        testagentdir=%s"                                         % \
                        (h.managementIp_, h.username_, h.password_, ansible_become_args, ansible_port_args, testagentdir)

                if ENV_HTTP_PROXY:
                    ansible_cmd_args = "%s http_proxy=%s https_proxy=%s" % \
                        (ansible_cmd_args, ENV_HTTP_PROXY, ENV_HTTPS_PROXY)

                ansible_cmd = "testagent.yaml -e '%s'" % ansible_cmd_args

                if hasattr(h, 'port_'):
                    thread = threading.Thread(target=ansible.execute_ansible,\
                        args=(h.managementIp_, h.username_, h.password_,\
                        testagentdir, ansible_cmd, lib_files, exc_info, h.port_))
                else:
                    thread = threading.Thread(target=ansible.execute_ansible,\
                        args=(h.managementIp_, h.username_, h.password_,\
                        testagentdir, ansible_cmd, lib_files, exc_info))

                # Wrap up old zstack logs in /var/log/zstack/
                #print('archive test log on host: [%s] \n' % h.managementIp_)
                #try:
                #    if hasattr(h, 'port_'):
                #        log.cleanup_log(h.managementIp_, h.username_, h.password_, h.port_)
                #    else:
                #        log.cleanup_log(h.managementIp_, h.username_, h.password_)
                #except Exception as e:
                #    print "clean up old testing logs meet execption on management node: %s" % h.managementIp_
                #    raise e

                thread.start()
            #if localhost is not in hosts, should do log archive for zstack
            log.cleanup_local_log()

            self._wait_for_thread_completion('install test agent', 200)

            for h in self.test_agent_hosts:
                if not linux.wait_callback_success(_wait_echo, h.managementIp_,
                                                   5, 0.2, True):
                    raise ActionError(
                        'testagent is not start up in 5s on %s, after it is deployed by ansible.'
                        % h.managementIp_)

        else:
            print('Deploy test agent in host: %s \n' % target.managementIp)
            if target.username != "root":
                ansible_cmd_args = "host=%s \
                        ansible_ssh_user=%s \
                        ansible_become=yes \
                        become_user=root \
                        ansible_become_pass=%s \
                        testagentdir=%s"                                         % \
                        (target.managementIp, target.username, target.password, testagentdir)
            else:
                ansible_cmd_args = "host=%s \
                        testagentdir=%s"                                         % \
                        (target.managementIp, testagentdir)
            if ENV_HTTP_PROXY:
                ansible_cmd_args = "%s http_proxy=%s https_proxy=%s" % \
                    (ansible_cmd_args, ENV_HTTP_PROXY, ENV_HTTPS_PROXY)

            ansible_cmd = "testagent.yaml -e '%s'" % ansible_cmd_args
            ansible.execute_ansible(target.managementIp, target.username, \
                    target.password, testagentdir, ansible_cmd, lib_files)
            if not linux.wait_callback_success(_wait_echo, target.managementIp,
                                               5, 0.2):
                raise ActionError(
                    'testagent is not start up in 5s on %s, after it is deployed by ansible.'
                    % target.managementIp)
    def deploy_test_agent(self, target=None):
        print('Deploy test agent\n')
        if not self.test_agent_path:
            print('Not find test_agent. Stop deploying test agent.\n')
            return
        
        testagentdir = None
        try:
            def untar_test_agent():
                tmpdir = tempfile.mkdtemp()
                shell.call('tar jxf %s -C %s' % (self.test_agent_path, tmpdir))
                shell.call('cd %s/zstacktestagent/; tar jcf pypi.tar.bz pypi' \
                        % tmpdir)
                return '%s/zstacktestagent' % tmpdir

            def _wait_echo(target_ip):
                try:
                    rspstr = http.json_dump_post(testagent.build_http_path(target_ip, host_plugin.ECHO_PATH))
                except:
                    print('zstack-testagent does not startup, will try again ...')
                    return False
                return True

            testagentdir = untar_test_agent()
            ansible.check_and_install_ansible()

            lib_files = ['testagent/zstacktestagent-1.0.0.tar.gz', \
                    'testagent/zstacklib-1.1.tar.gz' ]

            if not target:
                #default will deploy all test hosts.
                exc_info = []
                for h in self.test_agent_hosts:
                    print('Deploy test agent in host: [%s] \n' % h.managementIp_)
                    ansible_cmd_args = "host=%s \
                            pkg_testagent=zstacktestagent-1.0.0.tar.gz \
                            pkg_zstacklib=zstacklib-1.1.tar.gz \
                            pypi_source_tar=pypi.tar.bz" % \
                            h.managementIp_

                    if ENV_HTTP_PROXY:
                        ansible_cmd_args = "%s http_proxy=%s https_proxy=%s" % \
                            (ansible_cmd_args, ENV_HTTP_PROXY, ENV_HTTPS_PROXY)

                    ansible_cmd = "testagent.yaml -e '%s'" % ansible_cmd_args

                    thread = threading.Thread(target=ansible.execute_ansible,\
                        args=(h.managementIp_, h.username_, h.password_,\
                        testagentdir, ansible_cmd, lib_files, exc_info))

                    # Wrap up old zstack logs in /var/log/zstack/
                    print('archive test log on host: [%s] \n' % h.managementIp_)
                    try:
                        log.cleanup_log(h.managementIp_, h.username_, h.password_)
                    except Exception as e:
                        print "clean up old testing logs meet execption on management node: %s" % h.managementIp_
                        raise e

                    thread.start()
                #if localhost is not in hosts, should do log archive for zstack
                log.cleanup_local_log()

                self._wait_for_thread_completion('install test agent', 200)

                for h in self.test_agent_hosts:
                    if not linux.wait_callback_success(_wait_echo, h.managementIp_, 5, 0.2, True):
                        raise ActionError('testagent is not start up in 5s on %s, after it is deployed by ansible.' % h.managementIp_)

            else:
                print('Deploy test agent in host: %s \n' % target.managementIp)
                ansible_cmd_args = "host=%s \
                        pkg_testagent=zstacktestagent-1.0.0.tar.gz \
                        pkg_zstacklib=zstacklib-1.1.tar.gz \
                        pypi_source_tar=pypi.tar.bz" % \
                        target.managementIp
                if ENV_HTTP_PROXY:
                    ansible_cmd_args = "%s http_proxy=%s https_proxy=%s" % \
                        (ansible_cmd_args, ENV_HTTP_PROXY, ENV_HTTPS_PROXY)

                ansible_cmd = "testagent.yaml -e '%s'" % ansible_cmd_args
                ansible.execute_ansible(target.managementIp, target.username, \
                        target.password, testagentdir, ansible_cmd, lib_files)
                if not linux.wait_callback_success(_wait_echo, target.managementIp, 5, 0.2):
                    raise ActionError('testagent is not start up in 5s on %s, after it is deployed by ansible.' % target.managementIp)
                
        finally:
            if testagentdir:
                shell.call('rm -rf %s' % testagentdir)
Ejemplo n.º 7
0
    def deploy_test_agent(self, target=None):
        print('Deploy test agent\n')
        if not self.test_agent_path:
            print('Not find test_agent. Stop deploying test agent.\n')
            return
        
        testagentdir = None

        def _wait_echo(target_ip):
            try:
                rspstr = http.json_dump_post(testagent.build_http_path(target_ip, host_plugin.ECHO_PATH))
            except:
                print('zstack-testagent does not startup, will try again ...')
                return False
            return True

        testagentdir = self.test_agent_path
        ansible.check_and_install_ansible()

        lib_files = []

        if not target:
            #default will deploy all test hosts.
            exc_info = []
            for h in self.test_agent_hosts:
                print('Enable ansible connection in host: [%s] \n' % h.managementIp_)

                if hasattr(h, 'port_'):
                    ansible.enable_ansible_connection(h.managementIp_, h.username_, h.password_, exc_info, h.port_)
                else:
                    ansible.enable_ansible_connection(h.managementIp_, h.username_, h.password_, exc_info, 22)

            for h in self.test_agent_hosts:
                print('Deploy test agent in host: [%s] \n' % h.managementIp_)
                if h.username_ != 'root':
                    ansible_become_args = "ansible_become=yes become_user=root ansible_become_pass=%s" % (h.password_)
                else:
                    ansible_become_args = ""

                if hasattr(h, 'port_'):
                    ansible_port_args = "ansible_ssh_port=%s" % (h.port_)
                else:
                    ansible_port_args = ""

                ansible_cmd_args = "host=%s \
                        ansible_ssh_user=%s \
                        ansible_ssh_pass=%s \
                        %s \
                        %s \
                        testagentdir=%s" % \
                        (h.managementIp_, h.username_, h.password_, ansible_become_args, ansible_port_args, testagentdir)

                if ENV_HTTP_PROXY:
                    ansible_cmd_args = "%s http_proxy=%s https_proxy=%s" % \
                        (ansible_cmd_args, ENV_HTTP_PROXY, ENV_HTTPS_PROXY)

                ansible_cmd = "testagent.yaml -e '%s'" % ansible_cmd_args

                thread = threading.Thread(target=ansible.do_ansible,\
                     args=(testagentdir, ansible_cmd, lib_files, exc_info))
                # Wrap up old zstack logs in /var/log/zstack/
                #print('archive test log on host: [%s] \n' % h.managementIp_)
                #try:
                #    if hasattr(h, 'port_'):
                #        log.cleanup_log(h.managementIp_, h.username_, h.password_, h.port_)
                #    else:
                #        log.cleanup_log(h.managementIp_, h.username_, h.password_)
                #except Exception as e:
                #    print "clean up old testing logs meet execption on management node: %s" % h.managementIp_
                #    raise e

                thread.start()
            #if localhost is not in hosts, should do log archive for zstack
            log.cleanup_local_log()

            self._wait_for_thread_completion('install test agent', 200)

            for h in self.test_agent_hosts:
                if not linux.wait_callback_success(_wait_echo, h.managementIp_, 5, 0.2, True):
                    raise ActionError('testagent is not start up in 5s on %s, after it is deployed by ansible.' % h.managementIp_)

        else:
            print('Deploy test agent in host: %s \n' % target.managementIp)
	    if target.username != "root":
                ansible_cmd_args = "host=%s \
                        ansible_ssh_user=%s \
                        ansible_become=yes \
                        become_user=root \
                        ansible_become_pass=%s \
                        testagentdir=%s" % \
                        (target.managementIp, target.username, target.password, testagentdir)
            else:
                ansible_cmd_args = "host=%s \
                        testagentdir=%s" % \
                        (target.managementIp, testagentdir)
            if ENV_HTTP_PROXY:
                ansible_cmd_args = "%s http_proxy=%s https_proxy=%s" % \
                    (ansible_cmd_args, ENV_HTTP_PROXY, ENV_HTTPS_PROXY)

            ansible_cmd = "testagent.yaml -e '%s'" % ansible_cmd_args
            ansible.execute_ansible(target.managementIp, target.username, \
                    target.password, testagentdir, ansible_cmd, lib_files)
            if not linux.wait_callback_success(_wait_echo, target.managementIp, 5, 0.2):
                raise ActionError('testagent is not start up in 5s on %s, after it is deployed by ansible.' % target.managementIp)