Beispiel #1
0
    def run(self):
        try:
            nova = Node()
        except Exception:
            LOG.exception("Error initialising Nova connection")
            self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
            return self.msg

        LOG.info(
            "Assigning Floating IP {0} to {1}"
            .format(self.msg['ip'], self.msg['name'])
        )
        try:
            node_id = nova.get_node(self.msg['name'])
            LOG.info(
                'Node name {0} identified as ID {1}'
                .format(self.msg['name'], node_id)
            )
            nova.vip_assign(node_id, self.msg['ip'])

            self._wait_until_ip_assigned(nova, node_id, self.msg['ip'])

            if cfg.CONF['mgm']['tcp_check_port']:
                self.check_ip(self.msg['ip'],
                              cfg.CONF['mgm']['tcp_check_port'])
        except:
            LOG.exception(
                'Error assigning Floating IP {0} to {1}'
                .format(self.msg['ip'], self.msg['name'])
            )
            self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
            return self.msg

        self.msg[self.RESPONSE_FIELD] = self.RESPONSE_SUCCESS
        return self.msg
Beispiel #2
0
class TestLBaaSMgmNova(testtools.TestCase):
    def setUp(self):
        super(TestLBaaSMgmNova, self).setUp()
        self.api = Node(
            "username", "password", "auth_test", "tenant1", "region1",
            "default", "default", '1234', '100'
        )
        self.api.nova.management_url = "http://example.com"
        self.api.nova.auth_token = "token"

    def testCreateNode(self):
        with mock.patch.object(requests, "request", mock_request):
            with mock.patch('time.time', mock.Mock(return_value=1234)):
                data = self.api.build()
                self.assertEqual(data['id'], 417773)

    def testCreateNodeFail(self):
        with mock.patch.object(requests, "request", mock_bad_request):
            with mock.patch('time.time', mock.Mock(return_value=1234)):
                self.assertRaises(BuildError, self.api.build)

    def testDeleteNodeFail(self):
        with mock.patch.object(requests, "request", mock_bad_request):
            with mock.patch('time.time', mock.Mock(return_value=1234)):
                resp, data = self.api.delete('1234')
                self.assertFalse(resp)

    def testDeleteNodeSucceed(self):
        with mock.patch.object(requests, "request", mock_del_request):
            with mock.patch('time.time', mock.Mock(return_value=1234)):
                resp, data = self.api.delete('1234')
                self.assertTrue(resp)
Beispiel #3
0
    def run(self):
        try:
            nova = Node()
        except Exception:
            LOG.exception("Error initialising Nova connection")
            self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
            return self.msg

        LOG.info(
            "Removing Floating IP {0} from {1}"
            .format(self.msg['ip'], self.msg['name'])
        )
        try:
            node_id = nova.get_node(self.msg['name'])
            nova.vip_remove(node_id, self.msg['ip'])
        except:
            LOG.exception(
                'Error removing Floating IP {0} from {1}'
                .format(self.msg['ip'], self.msg['name'])
            )
            self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
            return self.msg

        self.msg[self.RESPONSE_FIELD] = self.RESPONSE_SUCCESS
        return self.msg
Beispiel #4
0
    def run(self):
        try:
            nova = Node()
        except Exception:
            LOG.exception("Error initialising Nova connection")
            self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
            return self.msg

        LOG.info(
            "Deleting a requested Nova instance {0}".format(self.msg['name'])
        )
        try:
            node_id = nova.get_node(self.msg['name'])
        except NotFound:
            LOG.error(
                "No node found for {0}".format(self.msg['name'])
            )
            self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
            return self.msg
        nova.delete(node_id)
        self.msg[self.RESPONSE_FIELD] = self.RESPONSE_SUCCESS
        LOG.info(
            'Deleted node {0}, id {1}'.format(self.msg['name'], node_id)
        )
        return self.msg
Beispiel #5
0
 def build_nodes(self, count, api):
     try:
         nova = Node(
             self.args.nova_user,
             self.args.nova_pass,
             self.args.nova_tenant,
             self.args.nova_auth_url,
             self.args.nova_region,
             self.args.nova_keyname,
             self.args.nova_secgroup,
             self.args.nova_image,
             self.args.nova_image_size,
             node_basename=self.args.node_basename
         )
     except Exception as exc:
         self.logger.error('Error initialising Nova connection {exc}'
             .format(exc=exc)
         )
         return
     while count > 0:
         try:
             data = nova.build()
         except BuildError as exc:
             self.logger.error('{0}, node {1}'
                 .format(exc.msg, exc.node_name)
             )
             if exc.node_id > 0:
                 self.logger.info('Storing node to try again later')
                 self.node_list.add(exc.node_id)
             else:
                 self.find_unknown(exc.node_name, nova)
             self.logger.warning('Aborting node building')
             return
         body = self.build_node_data(data)
         self.logger.info('Adding node {name} on {ip}'.format(
             name=body['name'], ip=body['publicIpAddr'])
         )
         status, response = api.add_node(body)
         if not status:
             self.logger.error(
                 'Could not upload node {name} to API server'
                 .format(name=data['name'])
             )
             self.logger.info('Storing node to try again later')
             self.node_list.add(data['id'])
             self.logger.warning('Aborting node building')
             return
         count = count - 1
Beispiel #6
0
    def run(self):
        try:
            nova = Node()
        except Exception:
            LOG.exception("Error initialising Nova connection")
            self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
            return self.msg

        LOG.info("Building a requested Nova instance")
        try:
            node_id = nova.build()
            LOG.info("Build command sent to Nova")
        except BuildError as exc:
            LOG.exception(
                "{0}, node {1}".format(exc.msg, exc.node_name)
            )
            name = exc.node_name
            # Node may have built despite error
            try:
                node_id = nova.get_node(name)
            except NotFound:
                LOG.error(
                    "No node found for {0}, giving up on it".format(name)
                )
                self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
                return self.msg
            except exceptions.ClientException:
                LOG.exception(
                    'Error getting failed node info from Nova for {0}'
                    .format(name)
                )
                self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
                return self.msg
        if node_id > 0:
            self._wait_until_node_ready(nova, node_id)
            if self.msg[self.RESPONSE_FIELD] == self.RESPONSE_SUCCESS:
                status = self._test_node(self.msg['name'])
                if not status:
                    self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
            return self.msg
        else:
            LOG.error(
                'Node build did not return an ID, cannot find it'
            )
            self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
            return self.msg
Beispiel #7
0
 def setUp(self):
     super(TestLBaaSMgmNova, self).setUp()
     self.api = Node(
         "username", "password", "auth_test", "tenant1", "region1",
         "default", "default", '1234', '100'
     )
     self.api.nova.management_url = "http://example.com"
     self.api.nova.auth_token = "token"
Beispiel #8
0
    def run(self):
        try:
            nova = Node()
        except Exception:
            LOG.exception("Error initialising Nova connection")
            self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
            return self.msg

        LOG.info("Creating a requested floating IP")
        try:
            ip_info = nova.vip_create()
        except exceptions.ClientException:
            LOG.exception(
                'Error getting a Floating IP'
            )
            self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
            return self.msg
        LOG.info("Floating IP {0} created".format(ip_info['id']))
        self.msg['id'] = ip_info['id']
        self.msg['ip'] = ip_info['ip']
        self.msg[self.RESPONSE_FIELD] = self.RESPONSE_SUCCESS
        return self.msg
Beispiel #9
0
    def run(self):
        try:
            nova = Node()
        except Exception:
            LOG.exception("Error initialising Nova connection")
            self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
            return self.msg

        LOG.info(
            "Deleting Floating IP {0}"
            .format(self.msg['ip'])
        )
        try:
            nova.vip_delete(self.msg['ip'])
        except:
            LOG.exception(
                'Error deleting Floating IP {0}'
                .format(self.msg['ip'])
            )
            self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
            return self.msg

        self.msg[self.RESPONSE_FIELD] = self.RESPONSE_SUCCESS
        return self.msg
Beispiel #10
0
    def retest_node(self, node_id, api):
        try:
            nova = Node(
                self.args.nova_user,
                self.args.nova_pass,
                self.args.nova_tenant,
                self.args.nova_auth_url,
                self.args.nova_region,
                self.args.nova_keyname,
                self.args.nova_secgroup,
                self.args.nova_image,
                self.args.nova_image_size,
                node_basename=self.args.node_basename
            )
        except Exception as exc:
            self.logger.error(
                'Error initialising Nova connection {exc}'
                .format(exc=exc)
            )
            return
        self.logger.info('Retrying node {0}'.format(node_id))
        try:
            resp, status = nova.status(node_id)
        except NotFound:
            self.logger.info(
                'Node {0} no longer exists, removing from list'
                .format(node_id)
            )
            self.node_list.delete(node_id)
            return
        except exceptions.ClientException as exc:
            self.logger.error(
                'Error getting status from Nova, exception {exc}'
                .format(exc=sys.exc_info()[0])
            )
            return

        if resp.status_code not in(200, 203):
            self.logger.error(
                'Error geting status from Nova, error {0}'
                .format(resp.status_code)
            )
            return
        status = status['server']
        if status['status'] == 'ACTIVE':
            name = status['name']
            body = self.build_node_data(status)
            status, response = api.add_node(body)
            if not status:
                self.logger.error(
                    'Could not upload node {name} to API server'
                    .format(name=name)
                )
            else:
                self.node_list.delete(node_id)
                self.logger.info('Node {0} added to API server'.format(name))
            return
        elif status['status'].startswith('BUILD'):
            self.logger.info(
                'Node {0} still building, ignoring'.format(node_id)
            )
            return
        else:
            self.logger.info(
                'Node {0} is bad, deleting'.format(node_id)
            )
            status, msg = nova.delete(node_id)
            if not status:
                self.logger.error(msg)
            else:
                self.logger.info('Delete successful')
                self.node_list.delete(node_id)