Ejemplo n.º 1
0
    def __get_task_response(self, task):
        if task['taskState'] in TASK_ERROR_STATES and task[
                'taskState'] != 'Warning':
            msg = None
            error_code = None
            if 'taskErrors' in task and len(task['taskErrors']) > 0:
                err = task['taskErrors'][0]
                if 'message' in err:
                    msg = err['message']

                error_code = err.get('errorCode')

            if msg:
                raise HPOneViewTaskError(msg, error_code)
            elif 'taskStatus' in task and task['taskStatus']:
                raise HPOneViewTaskError(task['taskStatus'], error_code)
            else:
                raise HPOneViewTaskError(MSG_UNKNOWN_EXCEPTION, error_code)

        deleted_resource = task['name'] in [
            'Delete', 'Remove', 'Delete server hardware type'
        ]

        if 'type' in task and task['type'].startswith(
                'Task') and 'name' in task and not deleted_resource:
            # get associated resource when is not a delete task
            task, entity = self.get_associated_resource(task)
            return entity

        if 'name' in task and task['name'] == 'Delete':
            # delete task return true
            return True

        logger.warning('Task completed, unknown response: ' + str(task))
        return task
Ejemplo n.º 2
0
 def wait4task(self, task, tout=60, verbose=False):
     count = 0
     if task is None:
         return None
     while self.is_task_running(task):
         if verbose:
             sys.stdout.write('Task still running after %d seconds   \r' %
                              count)
             sys.stdout.flush()
         time.sleep(1)
         count += 1
         if count > tout:
             raise HPOneViewTimeout(
                 'Waited ' + str(tout) +
                 ' seconds for task to complete, aborting')
     task = self._con.get(task['uri'])
     if task['taskState'] in TaskErrorStates and task[
             'taskState'] != 'Warning':
         err = task['taskErrors'][0]
         msg = err['message']
         if msg is not None:
             raise HPOneViewTaskError(msg)
         elif task['taskStatus'] is not None:
             raise HPOneViewTaskError(task['taskStatus'])
         else:
             raise HPOneViewTaskError('Unknown Exception')
     return task
Ejemplo n.º 3
0
 def test_task_error_constructor_with_string(self):
     exception = HPOneViewTaskError("A message string", 100)
     self.assertEqual(exception.msg, "A message string")
     self.assertEqual(exception.oneview_response, None)
     self.assertEqual(exception.args[0], "A message string")
     self.assertEqual(len(exception.args), 1)
     self.assertEqual(exception.error_code, 100)
from oneview_server_profile import ServerProfileModule
from oneview_server_profile import MAKE_COMPLIANT_NOT_SUPPORTED, SERVER_PROFILE_CREATED, REMEDIATED_COMPLIANCE, \
    ALREADY_COMPLIANT, SERVER_PROFILE_DELETED, SERVER_PROFILE_UPDATED, SERVER_ALREADY_UPDATED, \
    ERROR_ALLOCATE_SERVER_HARDWARE

SERVER_PROFILE_NAME = "Profile101"
SERVER_PROFILE_URI = "/rest/server-profiles/94B55683-173F-4B36-8FA6-EC250BA2328B"
SHT_URI = "/rest/server-hardware-types/94B55683-173F-4B36-8FA6-EC250BA2328B"
ENCLOSURE_GROUP_URI = "/rest/enclosure-groups/ad5e9e88-b858-4935-ba58-017d60a17c89"
TEMPLATE_URI = '/rest/server-profile-templates/9a156b04-fce8-40b0-b0cd-92ced1311dda'

MESSAGE_COMPLIANT_ERROR = MAKE_COMPLIANT_NOT_SUPPORTED.format(
    SERVER_PROFILE_NAME)
FAKE_MSG_ERROR = 'Fake message error'

TASK_ERROR = HPOneViewTaskError(msg=FAKE_MSG_ERROR,
                                error_code='AssignProfileToDeviceBayError')

BASIC_PROFILE = dict(name=SERVER_PROFILE_NAME,
                     serverHardwareTypeUri=SHT_URI,
                     enclosureGroupUri=ENCLOSURE_GROUP_URI,
                     uri=SERVER_PROFILE_URI)

BASIC_TEMPLATE = dict(
    name="Server-Template-7000",
    serverHardwareTypeUri=SHT_URI,
    enclosureGroupUri=ENCLOSURE_GROUP_URI,
    uri='/rest/server-profile-templates/9a156b04-fce8-40b0-b0cd-92ced1311dda')

PARAMS_FOR_PRESENT = dict(config='config.json',
                          state='present',
                          data=BASIC_PROFILE)