# Copyright 2011 Quanta Research Cambridge, Inc.
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
"""Defines various sub-classes of the `StressTestCase` and
`PendingServerAction` class. Sub-classes of StressTestCase implement various
API calls on the Nova cluster having to do with Server Actions. Each
sub-class will have a corresponding PendingServerAction. These pending
actions veriy that the API call was successful or not."""


# system imports
import random
import time

# local imports
import test_case
import pending_action
from tempest.exceptions import Duplicate
from utils.util import *


class TestRebootVM(test_case.StressTestCase):
    """Reboot a server"""

    def run(self, manager, state, *pargs, **kwargs):
        """
        Send an HTTP POST request to the nova cluster to reboot a random
        server. Update state of object in `state` variable to indicate that
        it is rebooting.
        `manager` : Manager object
        `state`      : `State` object describing our view of state of cluster
        `pargs`      : positional arguments
        `kwargs`     : keyword arguments, which include:
                       `timeout` : how long to wait before issuing Exception
                       `type`    : reboot type [SOFT or HARD] (default is SOFT)
        """

        vms = state.get_instances()
        active_vms = [v for k, v in vms.iteritems() if v and v[1] == 'ACTIVE']
        # no active vms, so return null
        if not active_vms:
            self._logger.info('no ACTIVE instances to reboot')
            return

        _reboot_arg = kwargs.get('type', 'SOFT')

        # select active vm to reboot and then send request to nova controller
        target = random.choice(active_vms)
        reboot_target = target[0]
        # It seems that doing a reboot when in reboot is an error.
        try:
            response, body = manager.servers_client.reboot(
                                                           reboot_target['id'],
                                                           _reboot_arg)
        except Duplicate:
            return

        if (response.status != 202):
            self._logger.error("response: %s" % response)
            raise Exception

        if _reboot_arg == 'SOFT':
            reboot_state = 'REBOOT'
        else:
            reboot_state = 'HARD_REBOOT'

        self._logger.info('waiting for machine %s to change to %s' %
                          (reboot_target['id'], reboot_state))

        return VerifyRebootVM(manager,
                              state,
                              reboot_target,
                              reboot_state=reboot_state)


class VerifyRebootVM(pending_action.PendingServerAction):
    """Class to verify that the reboot completed."""
    States = enum('REBOOT_CHECK', 'ACTIVE_CHECK')

    def __init__(self, manager, state, target_server,
                 reboot_state=None,
                 ip_addr=None):
        super(VerifyRebootVM, self).__init__(manager,
                                             state,
                                             target_server)
        self._reboot_state = reboot_state
        self._retry_state = self.States.REBOOT_CHECK

    def retry(self):
        """
        Check to see that the server of interest has actually rebooted. Update
        state to indicate that server is running again.
        """
        # don't run reboot verification if target machine has been
        # deleted or is going to be deleted
        if (self._target['id'] not in self._state.get_instances().keys() or
            self._state.get_instances()[self._target['id']][1] ==
            'TERMINATING'):
            self._logger.debug('machine %s is deleted or TERMINATING' %
                               self._target['id'])
            return True

        reboot_state = self._reboot_state
        if self._retry_state == self.States.REBOOT_CHECK:
            server_state = self._check_for_status(reboot_state)
            if server_state == reboot_state:
                self._logger.info('machine %s ACTIVE -> %s' %
                                  (self._target['id'], reboot_state))
                self._state.set_instance_state(self._target['id'],
                                              (self._target, reboot_state)
                                              )
                self._retry_state = self.States.ACTIVE_CHECK
            elif server_state == 'ACTIVE':
                # machine must have gone ACTIVE -> REBOOT ->ACTIVE
                self._retry_state = self.States.ACTIVE_CHECK

        elif self._retry_state == self.States.ACTIVE_CHECK:
            if not self._check_for_status('ACTIVE'):
                return False
        target = self._target
        self._logger.info('machine %s %s -> ACTIVE [%.1f secs elapsed]' %
                              (target['id'], reboot_state, self.elapsed()))
        self._state.set_instance_state(target['id'],
                                      (target, 'ACTIVE'))

        return True

# This code needs to be tested against a cluster that supports resize.
#class TestResizeVM(test_case.StressTestCase):
#    """Resize a server (change flavors)"""
#
#    def run(self, manager, state, *pargs, **kwargs):
#        """
#        Send an HTTP POST request to the nova cluster to resize a random
#        server. Update `state` to indicate server is rebooting.
#
#        `manager` : Manager object.
#        `state`      : `State` object describing our view of state of cluster
#        `pargs`      : positional arguments
#        `kwargs`     : keyword arguments, which include:
#                       `timeout` : how long to wait before issuing Exception
#        """
#
#        vms = state.get_instances()
#        active_vms = [v for k, v in vms.iteritems() if v and v[1] == 'ACTIVE']
#        # no active vms, so return null
#        if not active_vms:
#            self._logger.debug('no ACTIVE instances to resize')
#            return
#
#        target = random.choice(active_vms)
#        resize_target = target[0]
#        print resize_target
#
#        _timeout = kwargs.get('timeout', 600)
#
#        # determine current flavor type, and resize to a different type
#        # m1.tiny -> m1.small, m1.small -> m1.tiny
#        curr_size = int(resize_target['flavor']['id'])
#        if curr_size == 1:
#            new_size = 2
#        else:
#            new_size = 1
#        flavor_type = { 'flavorRef': new_size } # resize to m1.small
#
#        post_body = json.dumps({'resize' : flavor_type})
#        url = '/servers/%s/action' % resize_target['id']
#        (response, body) = manager.request('POST',
#                                              url,
#                                              body=post_body)
#
#        if (response.status != 202):
#            self._logger.error("response: %s" % response)
#            raise Exception
#
#        state_name = check_for_status(manager, resize_target, 'RESIZE')
#
#        if state_name == 'RESIZE':
#            self._logger.info('machine %s: ACTIVE -> RESIZE' %
#                              resize_target['id'])
#            state.set_instance_state(resize_target['id'],
#                                    (resize_target, 'RESIZE'))
#
#        return VerifyResizeVM(manager,
#                              state,
#                              resize_target,
#                              state_name=state_name,
#                              timeout=_timeout)
#
#class VerifyResizeVM(pending_action.PendingServerAction):
#    """Verify that resizing of a VM was successful"""
#    States = enum('VERIFY_RESIZE_CHECK', 'ACTIVE_CHECK')
#
#    def __init__(self, manager, state, created_server,
#                 state_name=None,
#                 timeout=300):
#        super(VerifyResizeVM, self).__init__(manager,
#                                             state,
#                                             created_server,
#                                             timeout=timeout)
#        self._retry_state = self.States.VERIFY_RESIZE_CHECK
#        self._state_name = state_name
#
#    def retry(self):
#        """
#        Check to see that the server was actually resized. And change `state`
#        of server to running again.
#        """
#        # don't run resize if target machine has been deleted
#        # or is going to be deleted
#        if (self._target['id'] not in self._state.get_instances().keys() or
#            self._state.get_instances()[self._target['id']][1] ==
#           'TERMINATING'):
#            self._logger.debug('machine %s is deleted or TERMINATING' %
#                               self._target['id'])
#            return True
#
#        if self._retry_state == self.States.VERIFY_RESIZE_CHECK:
#            if self._check_for_status('VERIFY_RESIZE') == 'VERIFY_RESIZE':
#                # now issue command to CONFIRM RESIZE
#                post_body = json.dumps({'confirmResize' : null})
#                url = '/servers/%s/action' % self._target['id']
#                (response, body) = manager.request('POST',
#                                                      url,
#                                                      body=post_body)
#                if (response.status != 204):
#                    self._logger.error("response: %s" % response)
#                    raise Exception
#
#                self._logger.info(
#                    'CONFIRMING RESIZE of machine %s [%.1f secs elapsed]' %
#                    (self._target['id'], self.elapsed())
#                    )
#                state.set_instance_state(self._target['id'],
#                                        (self._target, 'CONFIRM_RESIZE'))
#
#                # change states
#                self._retry_state = self.States.ACTIVE_CHECK
#
#            return False
#
#        elif self._retry_state == self.States.ACTIVE_CHECK:
#            if not self._check_manager("ACTIVE"):
#                return False
#            else:
#                server = self._manager.get_server(self._target['id'])
#
#                # Find private IP of server?
#                try:
#                    (_, network) = server['addresses'].popitem()
#                    ip = network[0]['addr']
#                except KeyError:
#                    self._logger.error(
#                        'could not get ip address for machine %s' %
#                        self._target['id']
#                        )
#                    raise Exception
#
#                self._logger.info(
#                    'machine %s: VERIFY_RESIZE -> ACTIVE [%.1f sec elapsed]' %
#                    (self._target['id'], self.elapsed())
#                    )
#                self._state.set_instance_state(self._target['id'],
#                                              (self._target, 'ACTIVE'))
#
#                return True
#
#        else:
#            # should never get here
#            self._logger.error('Unexpected state')
#            raise Exception
