Ejemplo n.º 1
0
def action(server_os, client=None):
    # Return whether or not to trigger init notification
    trigger_notify = False

    xen_events = utils.list_xen_events(client)
    if len(xen_events) == 0:
        # if no xen_events then trigger the notification
        trigger_notify = True

    for uuid in xen_events:
        event = utils.get_xen_event(uuid, client)
        log.info('Event: {0} -> {1}'.format(uuid, event['name']))
        command_return = ('', '')
        if hasattr(server_os, event['name']):
            run_command = getattr(server_os, event['name'])
            command_return = run_command(event['name'], event['value'], client)

        utils.remove_xenhost_event(uuid, client)
        message = command_return[1]
        return_code = command_return[0]
        if command_return[0] == '':
            return_code = '0'

        utils.update_xenguest_event(uuid, {
            'message': message,
            'returncode': return_code
        }, client)
        log.info('Returning {{"message": "{0}", "returncode": "{1}"}}'.format(
            message, return_code))
        if event['name'] == 'resetnetwork':
            # If the network has completed setup then trigger the notification
            trigger_notify = True

    return trigger_notify
Ejemplo n.º 2
0
def action(serveros):
    for uuid in utils.list_xen_events():
        event = utils.get_xen_event(uuid)
        log.info('Event: {0} -> {1}'.format(uuid, event['name']))
        returncode = ()
        if hasattr(serveros, event['name']):
            cmd = getattr(serveros, event['name'])
            returncode = cmd(event['name'], event['value'])

        utils.remove_xenhost_event(uuid)
        if returncode:
            utils.update_xenguest_event(uuid, {
                'message': returncode[1],
                'returncode': returncode[0]
            })
            log.info(
                'Returning {{"message": "{1}", "returncode": "{0}"}}'.format(
                    *returncode))
        else:
            utils.update_xenguest_event(uuid, {
                'message': '',
                'returncode': '0'
            })
            log.info('Returning {"message": "", "returncode": ""}')
        action(serveros)
Ejemplo n.º 3
0
def action(server_os, client=None):
    for uuid in utils.list_xen_events(client):
        event = utils.get_xen_event(uuid, client)
        log.info('Event: {0} -> {1}'.format(uuid, event['name']))
        command_return = ('', '')
        if hasattr(server_os, event['name']):
            run_command = getattr(server_os, event['name'])
            command_return = run_command(event['name'], event['value'], client)

        utils.remove_xenhost_event(uuid, client)
        message = command_return[1]
        return_code = command_return[0]
        if command_return[0] == '':
            return_code = '0'

        utils.update_xenguest_event(
            uuid,
            {'message': message, 'returncode': return_code},
            client
        )
        log.info(
            'Returning {{"message": "{0}", "returncode": "{1}"}}'.format(
                message,
                return_code
            )
        )
Ejemplo n.º 4
0
    def test_get_host_event_popen_exception(self):
        host_event_id = '748dee41-c47f-4ec7-b2cd-037e51da4031'
        with mock.patch('novaagent.xenstore.xenstore.Popen',
                        side_effect=ValueError):
            event_details = utils.get_xen_event(host_event_id, None)

        self.assertEqual(event_details, None,
                         'Event details should be None on exception')
Ejemplo n.º 5
0
 def test_get_host_event_exception(self):
     host_event_id = '748dee41-c47f-4ec7-b2cd-037e51da4031'
     client = ClientTest(None)
     event_details = utils.get_xen_event(host_event_id, client)
     self.assertEqual(
         event_details,
         None,
         'Event details should be None on exception'
     )
Ejemplo n.º 6
0
 def test_get_host_event(self):
     host_event_id = '748dee41-c47f-4ec7-b2cd-037e51da4031'
     event_check = {
         "name": "keyinit",
         "value": "68436575764933852815830951574296"
     }
     client = ClientTest(xen_data.get_xen_host_event_details())
     event_details = utils.get_xen_event(host_event_id, client)
     self.assertEqual(event_check, event_details,
                      'Event details do not match expected value')
Ejemplo n.º 7
0
    def test_get_host_event_failure_popen(self):
        host_event_id = '748dee41-c47f-4ec7-b2cd-037e51da4031'
        with mock.patch('novaagent.xenstore.xenstore.Popen') as popen:
            popen.return_value.communicate.return_value = (b'', '')
            popen.return_value.returncode = 1

            event_details = utils.get_xen_event(host_event_id, None)

        self.assertEqual(
            event_details, None,
            'Event details do not match expected value after failure')
Ejemplo n.º 8
0
    def test_get_host_event_popen(self):
        host_event_id = '748dee41-c47f-4ec7-b2cd-037e51da4031'
        event_check = {
            "name": "keyinit",
            "value": "68436575764933852815830951574296"
        }
        with mock.patch('novaagent.xenstore.xenstore.Popen') as popen:
            popen.return_value.communicate.return_value = (
                utils_data.get_xen_host_event_details())
            popen.return_value.returncode = 0
            event_details = utils.get_xen_event(host_event_id, None)

        self.assertEqual(event_check, event_details,
                         'Event details do not match expected value')
Ejemplo n.º 9
0
def action(serveros):
    for uuid in utils.list_xen_events():
        event = utils.get_xen_event(uuid)
        log.info('Event: {0} -> {1}'.format(uuid, event['name']))
        returncode = ()
        if hasattr(serveros, event['name']):
            cmd = getattr(serveros, event['name'])
            returncode = cmd(event['name'], event['value'])

        utils.remove_xenhost_event(uuid)
        if returncode:
            utils.update_xenguest_event(uuid, {'message': returncode[1], 'returncode': returncode[0]})
            log.info('Returning {{"message": "{1}", "returncode": "{0}"}}'.format(*returncode))
        else:
            utils.update_xenguest_event(uuid, {'message': '', 'returncode': '0'})
            log.info('Returning {"message": "", "returncode": ""}')
        action(serveros)