Exemplo n.º 1
0
    def stop_test_POST(self, *args):
        session_id = args[0]
        if KBSessionManager.get(session_id).kb_status != 'RUNNING':
            response.status = 403
            response.text = u"Unable to stop the tests when status is not at RUNNING."
            return response.text

        kb_session = KBSessionManager.get(session_id)
        kb_session.kb_status = 'STOPPING'
        try:
            kb_session.kloudbuster.stop_test()
        except Exception:
            LOG.warning(traceback.format_exc())
            kb_session.kb_status = 'ERROR'

        return "OK!"
Exemplo n.º 2
0
    def az_list(self, *args):
        session_id = args[0]
        kb_session = KBSessionManager.get(session_id)
        kloudbuster = kb_session.kloudbuster
        ret_dict = {}
        ret_dict['server'] = kloudbuster.get_az_list(kloudbuster.server_cred)
        if not kloudbuster.single_cloud:
            ret_dict['client'] = kloudbuster.get_az_list(kloudbuster.client_cred)

        return json.dumps(ret_dict)
Exemplo n.º 3
0
    def report(self, *args, **kwargs):
        session_id = args[0]
        final = True if kwargs.get('final', '').lower() == 'true' else False
        preport = [] if final else None
        kb_session = KBSessionManager.get(session_id)
        if kb_session.kloudbuster and kb_session.kloudbuster.kb_runner:
            preport = kb_session.kloudbuster.final_result\
                if final else kb_session.kloudbuster.kb_runner.report

        return json.dumps(preport)
Exemplo n.º 4
0
    def cleanup_POST(self, *args):
        session_id = args[0]
        allowed_status = ['STAGED', 'ERROR']
        if KBSessionManager.get(session_id).kb_status == 'READY':
            response.status = 403
            response.text = u"No resources has been staged, cleanup is not needed."
            return response.text
        if KBSessionManager.get(session_id).kb_status not in allowed_status:
            response.status = 403
            response.text = u"The session you specified is busy, please wait until "\
                "current operation is finished."
            return response.text

        self.kb_thread = threading.Thread(
            target=self.kb_cleanup_thread_handler, args=[session_id])
        self.kb_thread.daemon = True
        self.kb_thread.start()

        return "OK!"
Exemplo n.º 5
0
    def az_list(self, *args):
        session_id = args[0]
        kb_session = KBSessionManager.get(session_id)
        kloudbuster = kb_session.kloudbuster
        ret_dict = {}
        ret_dict['server'] = kloudbuster.get_az_list(kloudbuster.server_cred)
        if not kloudbuster.single_cloud:
            ret_dict['client'] = kloudbuster.get_az_list(kloudbuster.client_cred)

        return json.dumps(ret_dict)
Exemplo n.º 6
0
 def running_config_DELETE(self, *args):
     session_id = args[0]
     kb_session = KBSessionManager.get(session_id)
     status = kb_session.kb_status
     if status != "READY":
         response.status = 403
         response.text = u"Session can be destroyed only if it is at READY."
         return response.text
     if kb_session.kloudbuster:
         kb_session.kloudbuster.dispose()
     KBSessionManager.delete(session_id)
     return "OK!"
Exemplo n.º 7
0
 def running_config_DELETE(self, *args):
     session_id = args[0]
     kb_session = KBSessionManager.get(session_id)
     status = kb_session.kb_status
     if status != "READY":
         response.status = 403
         response.text = u"Session can be destroyed only if it is at READY."
         return response.text
     if kb_session.kloudbuster:
         kb_session.kloudbuster.dispose()
     KBSessionManager.delete(session_id)
     return "OK!"
Exemplo n.º 8
0
 def status(self, *args):
     session_id = args[0]
     kb_session = KBSessionManager.get(session_id)
     status = kb_session.kb_status
     kloudbuster = kb_session.kloudbuster
     status_dict = {'status': status}
     if status == "STAGING":
         status_dict['server_vm_count'] =\
             getattr(getattr(kloudbuster, 'kloud', None), 'vm_up_count', 0)
         status_dict[
             'client_vm_count'] = kloudbuster.testing_kloud.vm_up_count
     return json.dumps(status_dict)
Exemplo n.º 9
0
    def kb_cleanup_thread_handler(self, session_id):
        kb_session = KBSessionManager.get(session_id)
        kb_session.kb_status = 'CLEANING'
        kloudbuster = kb_session.kloudbuster
        try:
            kloudbuster.cleanup()
            kloudbuster.final_result = []
        except Exception:
            pass

        kb_session.first_run = True
        kb_session.kb_status = 'READY'
Exemplo n.º 10
0
 def kb_run_test_thread_handler(self, session_id):
     kb_session = KBSessionManager.get(session_id)
     kb_session.kb_status = 'RUNNING'
     kloudbuster = kb_session.kloudbuster
     try:
         kb_session.sync_cfg(["client_cfg"])
         kloudbuster.run_test(test_only=not kb_session.first_run)
         kb_session.first_run = False
         kb_session.kb_status = 'STAGED'
     except Exception:
         LOG.warning(traceback.format_exc())
         kb_session.kb_status = 'ERROR'
Exemplo n.º 11
0
 def kb_stage_thread_handler(self, session_id):
     kb_session = KBSessionManager.get(session_id)
     kb_session.kb_status = 'STAGING'
     try:
         if kb_session.kloudbuster.check_and_upload_images():
             kb_session.sync_cfg(
                 ["server_cfg", "client_cfg", "topo_cfg", "tenants_list"])
             kb_session.kloudbuster.stage()
         kb_session.kb_status = 'STAGED'
     except Exception:
         LOG.warning(traceback.format_exc())
         kb_session.kb_status = 'ERROR'
Exemplo n.º 12
0
    def running_config_PUT(self, *args, **kwargs):
        session_id = args[0]
        status = KBSessionManager.get(session_id).kb_status
        try:
            user_config = json.loads(kwargs['arg'])
            allowed_status = ['READY']
        except Exception as e:
            response.status = 400
            response.text = u"Invalid JSON: \n%s" % (e.message)
            return response.text

        # http_tool_configs and storage_tool_config for client VMs is allowed to be
        # changed under "STAGED" status
        if ('kb_cfg' in user_config and len(user_config['kb_cfg']) == 1) and \
           ('client' in user_config['kb_cfg'] and len(user_config['kb_cfg']['client']) == 1) and \
           ('http_tool_configs' in user_config['kb_cfg']['client'] or
           'storage_tool_configs' in user_config['kb_cfg']['client']):
            allowed_status.append('STAGED')

        if status in allowed_status:
            # Expectation:
            # {
            #   'kb_cfg': {<USER_OVERRIDED_CONFIGS>},
            #   'topo_cfg': {<TOPOLOGY_CONFIGS>}
            #   'tenants_cfg': {<TENANT_AND_USER_LISTS_FOR_REUSING>}
            # }
            try:
                kb_config = KBSessionManager.get(session_id).kb_config
                self.fix_config(kb_config, user_config)
            except Exception:
                response.status = 400
                response.text = u"Error while parsing configurations: \n%s" %\
                    (traceback.format_exc())
                return response.text
        else:
            response.status = 403
            response.text = u"Cannot update configuration if KloudBuster is not at READY."
            return response.text

        return "OK!"
Exemplo n.º 13
0
    def running_config_PUT(self, *args, **kwargs):
        session_id = args[0]
        status = KBSessionManager.get(session_id).kb_status
        try:
            user_config = json.loads(kwargs['arg'])
            allowed_status = ['READY']
        except Exception as e:
            response.status = 400
            response.text = u"Invalid JSON: \n%s" % (e.message)
            return response.text

        # http_tool_configs and storage_tool_config for client VMs is allowed to be
        # changed under "STAGED" status
        if ('kb_cfg' in user_config and len(user_config['kb_cfg']) == 1) and \
           ('client' in user_config['kb_cfg'] and len(user_config['kb_cfg']['client']) == 1) and \
           ('http_tool_configs' in user_config['kb_cfg']['client'] or
           'storage_tool_configs' in user_config['kb_cfg']['client']):
            allowed_status.append('STAGED')

        if status in allowed_status:
            # Expectation:
            # {
            #   'kb_cfg': {<USER_OVERRIDED_CONFIGS>},
            #   'topo_cfg': {<TOPOLOGY_CONFIGS>}
            #   'tenants_cfg': {<TENANT_AND_USER_LISTS_FOR_REUSING>}
            # }
            try:
                kb_config = KBSessionManager.get(session_id).kb_config
                self.fix_config(kb_config, user_config)
            except Exception:
                response.status = 400
                response.text = u"Error while parsing configurations: \n%s" %\
                    (traceback.format_exc())
                return response.text
        else:
            response.status = 403
            response.text = u"Cannot update configuration if KloudBuster is not at READY."
            return response.text

        return "OK!"
Exemplo n.º 14
0
    def run_test_POST(self, *args):
        session_id = args[0]
        if KBSessionManager.get(session_id).kb_status != 'STAGED':
            response.status = 403
            response.text = u"Unable to start the tests when status is not at STAGED."
            return response.text

        self.kb_thread = threading.Thread(
            target=self.kb_run_test_thread_handler, args=[session_id])
        self.kb_thread.daemon = True
        self.kb_thread.start()

        return "OK!"
Exemplo n.º 15
0
    def stage_POST(self, *args):
        session_id = args[0]
        if KBSessionManager.get(session_id).kb_status != 'READY':
            response.status = 403
            response.text = u"Unable to stage resources when status is not READY."
            return response.text

        self.kb_thread = threading.Thread(target=self.kb_stage_thread_handler,
                                          args=[session_id])
        self.kb_thread.daemon = True
        self.kb_thread.start()

        return "OK!"
Exemplo n.º 16
0
    def log(self, *args, **kwargs):
        session_id = args[0]
        offset = kwargs.get('offset', 0)
        try:
            offset = int(offset)
        except ValueError:
            response.status = 400
            response.text = u"Parameter 'offset' is invalid."
            return response.text

        kb_session = KBSessionManager.get(session_id)
        plog = kb_session.kloudbuster.dump_logs(offset=offset)\
            if kb_session.kloudbuster else ""
        return json.dumps(plog)
Exemplo n.º 17
0
 def running_config_DELETE(self, *args):
     if len(args):
         session_id = args[0]
     else:
         response.status = 400
         response.text = u"Please specify the session_id."
         return response.text
     if KBSessionManager.has(session_id):
         kb_session = KBSessionManager.get(session_id)
         if kb_session.kloudbuster:
             kb_session.kloudbuster.dispose()
         KBSessionManager.delete(session_id)
         return "OK!"
     else:
         response.status = 404
         response.text = u"Session ID is not found or invalid."
         return response.text
Exemplo n.º 18
0
 def running_config(self, *args):
     if len(args):
         session_id = args[0]
     else:
         response.status = 400
         response.text = u"Please specify the session_id."
         return response.text
     if KBSessionManager.has(session_id):
         kb_config_obj = KBSessionManager.get(session_id).kb_config
         config_scale = kb_config_obj.config_scale
         config_scale["server"] = kb_config_obj.server_cfg
         config_scale["client"] = kb_config_obj.client_cfg
         config_scale = eval(str(config_scale))
         return json.dumps(config_scale)
     else:
         response.status = 404
         response.text = u"Session ID is not found or invalid."
         return response.text
Exemplo n.º 19
0
 def running_config(self, *args):
     session_id = args[0]
     kb_config_obj = KBSessionManager.get(session_id).kb_config
     config_scale = dict(kb_config_obj.config_scale)
     return json.dumps(config_scale)
Exemplo n.º 20
0
 def topology_config(self, *args):
     session_id = args[0]
     kb_config_obj = KBSessionManager.get(session_id).kb_config
     return json.dumps(kb_config_obj.topo_cfg)
Exemplo n.º 21
0
 def running_config(self, *args):
     session_id = args[0]
     kb_config_obj = KBSessionManager.get(session_id).kb_config
     config_scale = dict(kb_config_obj.config_scale)
     return json.dumps(config_scale)
Exemplo n.º 22
0
 def topology_config(self, *args):
     session_id = args[0]
     kb_config_obj = KBSessionManager.get(session_id).kb_config
     return json.dumps(kb_config_obj.topo_cfg)