Browse Source

Merge "Switch Octavia API calls to openstacksdk"

Zuul 1 month ago
parent
commit
21a0a2673c

+ 15
- 24
kuryr_kubernetes/clients.py View File

@@ -16,23 +16,27 @@
16 16
 import os
17 17
 
18 18
 from kuryr.lib import utils
19
+from openstack import connection
19 20
 
20 21
 from kuryr_kubernetes import config
21 22
 from kuryr_kubernetes import k8s_client
22
-from neutronclient import client as n_client
23 23
 
24 24
 _clients = {}
25 25
 _NEUTRON_CLIENT = 'neutron-client'
26
-_LB_CLIENT = 'load-balancer-client'
27 26
 _KUBERNETES_CLIENT = 'kubernetes-client'
27
+_OPENSTACKSDK = 'openstacksdk'
28 28
 
29 29
 
30 30
 def get_neutron_client():
31 31
     return _clients[_NEUTRON_CLIENT]
32 32
 
33 33
 
34
+def get_openstacksdk():
35
+    return _clients[_OPENSTACKSDK]
36
+
37
+
34 38
 def get_loadbalancer_client():
35
-    return _clients[_LB_CLIENT]
39
+    return get_openstacksdk().load_balancer
36 40
 
37 41
 
38 42
 def get_kubernetes_client():
@@ -41,34 +45,14 @@ def get_kubernetes_client():
41 45
 
42 46
 def setup_clients():
43 47
     setup_neutron_client()
44
-    setup_loadbalancer_client()
45 48
     setup_kubernetes_client()
49
+    setup_openstacksdk()
46 50
 
47 51
 
48 52
 def setup_neutron_client():
49 53
     _clients[_NEUTRON_CLIENT] = utils.get_neutron_client()
50 54
 
51 55
 
52
-def setup_loadbalancer_client():
53
-    neutron_client = get_neutron_client()
54
-    if any(ext['alias'] == 'lbaasv2' for
55
-           ext in neutron_client.list_extensions()['extensions']):
56
-        _clients[_LB_CLIENT] = neutron_client
57
-        neutron_client.cascading_capable = False
58
-    else:
59
-        # Since Octavia is lbaasv2 API compatible (A superset of it) we'll just
60
-        # wire an extra neutron client instance to point to it
61
-        lbaas_client = utils.get_neutron_client()
62
-        conf_group = utils.kuryr_config.neutron_group.name
63
-        auth_plugin = utils.get_auth_plugin(conf_group)
64
-        octo_httpclient = n_client.construct_http_client(
65
-            session=utils.get_keystone_session(conf_group, auth_plugin),
66
-            service_type='load-balancer')
67
-        lbaas_client.httpclient = octo_httpclient
68
-        _clients[_LB_CLIENT] = lbaas_client
69
-        lbaas_client.cascading_capable = True
70
-
71
-
72 56
 def setup_kubernetes_client():
73 57
     if config.CONF.kubernetes.api_root:
74 58
         api_root = config.CONF.kubernetes.api_root
@@ -79,3 +63,10 @@ def setup_kubernetes_client():
79 63
         port = os.environ['KUBERNETES_SERVICE_PORT_HTTPS']
80 64
         api_root = "https://%s:%s" % (host, port)
81 65
     _clients[_KUBERNETES_CLIENT] = k8s_client.K8sClient(api_root)
66
+
67
+
68
+def setup_openstacksdk():
69
+    auth_plugin = utils.get_auth_plugin('neutron')
70
+    session = utils.get_keystone_session('neutron', auth_plugin)
71
+    conn = connection.Connection(session=session)
72
+    _clients[_OPENSTACKSDK] = conn

+ 110
- 154
kuryr_kubernetes/controller/drivers/lbaasv2.py View File

@@ -14,14 +14,12 @@
14 14
 #    under the License.
15 15
 
16 16
 import random
17
-import six
18
-import sys
19 17
 import time
20
-import traceback
21 18
 
22 19
 import requests
23 20
 
24 21
 from neutronclient.common import exceptions as n_exc
22
+from openstack import exceptions as o_exc
25 23
 from oslo_config import cfg
26 24
 from oslo_log import log as logging
27 25
 from oslo_utils import timeutils
@@ -53,11 +51,6 @@ _LB_STS_POLL_SLOW_INTERVAL = 3
53 51
 class LBaaSv2Driver(base.LBaaSDriver):
54 52
     """LBaaSv2Driver implements LBaaSDriver for Neutron LBaaSv2 API."""
55 53
 
56
-    @property
57
-    def cascading_capable(self):
58
-        lbaas = clients.get_loadbalancer_client()
59
-        return lbaas.cascading_capable
60
-
61 54
     def get_service_loadbalancer_name(self, namespace, svc_name):
62 55
         return "%s/%s" % (namespace, svc_name)
63 56
 
@@ -84,17 +77,12 @@ class LBaaSv2Driver(base.LBaaSDriver):
84 77
     def release_loadbalancer(self, loadbalancer):
85 78
         neutron = clients.get_neutron_client()
86 79
         lbaas = clients.get_loadbalancer_client()
87
-        if lbaas.cascading_capable:
88
-            self._release(
89
-                loadbalancer,
90
-                loadbalancer,
91
-                lbaas.delete,
92
-                lbaas.lbaas_loadbalancer_path % loadbalancer.id,
93
-                params={'cascade': True})
94
-
95
-        else:
96
-            self._release(loadbalancer, loadbalancer,
97
-                          lbaas.delete_loadbalancer, loadbalancer.id)
80
+        self._release(
81
+            loadbalancer,
82
+            loadbalancer,
83
+            lbaas.delete_load_balancer,
84
+            loadbalancer.id,
85
+            cascade=True)
98 86
 
99 87
         sg_id = self._find_listeners_sg(loadbalancer)
100 88
         if sg_id:
@@ -394,7 +382,7 @@ class LBaaSv2Driver(base.LBaaSDriver):
394 382
             result = self._ensure_provisioned(
395 383
                 loadbalancer, listener, self._create_listener,
396 384
                 self._find_listener, _LB_STS_POLL_SLOW_INTERVAL)
397
-        except n_exc.BadRequest:
385
+        except o_exc.BadRequestException:
398 386
             LOG.info("Listener creation failed, most probably because "
399 387
                      "protocol %(prot)s is not supported", {'prot': protocol})
400 388
             return None
@@ -449,9 +437,7 @@ class LBaaSv2Driver(base.LBaaSDriver):
449 437
 
450 438
     def release_pool(self, loadbalancer, pool):
451 439
         lbaas = clients.get_loadbalancer_client()
452
-        self._release(loadbalancer, pool,
453
-                      lbaas.delete_lbaas_pool,
454
-                      pool.id)
440
+        self._release(loadbalancer, pool, lbaas.delete_pool, pool.id)
455 441
 
456 442
     def ensure_member(self, loadbalancer, pool,
457 443
                       subnet_id, ip, port, target_ref_namespace,
@@ -480,9 +466,8 @@ class LBaaSv2Driver(base.LBaaSDriver):
480 466
 
481 467
     def release_member(self, loadbalancer, member):
482 468
         lbaas = clients.get_loadbalancer_client()
483
-        self._release(loadbalancer, member,
484
-                      lbaas.delete_lbaas_member,
485
-                      member.id, member.pool_id)
469
+        self._release(loadbalancer, member, lbaas.delete_member, member.id,
470
+                      member.pool_id)
486 471
 
487 472
     def _get_vip_port(self, loadbalancer):
488 473
         neutron = clients.get_neutron_client()
@@ -502,71 +487,73 @@ class LBaaSv2Driver(base.LBaaSDriver):
502 487
     def _create_loadbalancer(self, loadbalancer):
503 488
         lbaas = clients.get_loadbalancer_client()
504 489
 
505
-        request = {'loadbalancer': {
490
+        request = {
506 491
             'name': loadbalancer.name,
507 492
             'project_id': loadbalancer.project_id,
508 493
             'vip_address': str(loadbalancer.ip),
509
-            'vip_subnet_id': loadbalancer.subnet_id}}
494
+            'vip_subnet_id': loadbalancer.subnet_id,
495
+        }
510 496
 
511 497
         if loadbalancer.provider is not None:
512
-            request['loadbalancer']['provider'] = loadbalancer.provider
498
+            request['provider'] = loadbalancer.provider
513 499
 
514
-        response = lbaas.create_loadbalancer(request)
515
-        loadbalancer.id = response['loadbalancer']['id']
500
+        response = lbaas.create_load_balancer(**request)
501
+        loadbalancer.id = response['id']
516 502
         loadbalancer.port_id = self._get_vip_port(loadbalancer).get("id")
517 503
         if (loadbalancer.provider is not None and
518
-                loadbalancer.provider != response['loadbalancer']['provider']):
504
+                loadbalancer.provider != response['provider']):
519 505
             LOG.error("Request provider(%s) != Response provider(%s)",
520 506
                       loadbalancer.provider,
521
-                      response['loadbalancer']['provider'])
507
+                      response['provider'])
522 508
             return None
523
-        loadbalancer.provider = response['loadbalancer']['provider']
509
+        loadbalancer.provider = response['provider']
524 510
         return loadbalancer
525 511
 
526 512
     def _find_loadbalancer(self, loadbalancer):
527 513
         lbaas = clients.get_loadbalancer_client()
528
-        response = lbaas.list_loadbalancers(
514
+        response = lbaas.load_balancers(
529 515
             name=loadbalancer.name,
530 516
             project_id=loadbalancer.project_id,
531 517
             vip_address=str(loadbalancer.ip),
532 518
             vip_subnet_id=loadbalancer.subnet_id)
533 519
 
534 520
         try:
535
-            loadbalancer.id = response['loadbalancers'][0]['id']
521
+            os_lb = next(response)  # openstacksdk returns a generator
522
+            loadbalancer.id = os_lb['id']
536 523
             loadbalancer.port_id = self._get_vip_port(loadbalancer).get("id")
537
-            loadbalancer.provider = response['loadbalancers'][0]['provider']
538
-            if (response['loadbalancers'][0]['provisioning_status'] ==
539
-                    'ERROR'):
524
+            loadbalancer.provider = os_lb['provider']
525
+            if os_lb['provisioning_status'] == 'ERROR':
540 526
                 self.release_loadbalancer(loadbalancer)
541 527
                 return None
542
-        except (KeyError, IndexError):
528
+        except (KeyError, StopIteration):
543 529
             return None
544 530
 
545 531
         return loadbalancer
546 532
 
547 533
     def _create_listener(self, listener):
548 534
         lbaas = clients.get_loadbalancer_client()
549
-        response = lbaas.create_listener({'listener': {
550
-            'name': listener.name,
551
-            'project_id': listener.project_id,
552
-            'loadbalancer_id': listener.loadbalancer_id,
553
-            'protocol': listener.protocol,
554
-            'protocol_port': listener.port}})
555
-        listener.id = response['listener']['id']
535
+        response = lbaas.create_listener(
536
+            name=listener.name,
537
+            project_id=listener.project_id,
538
+            load_balancer_id=listener.loadbalancer_id,
539
+            protocol=listener.protocol,
540
+            protocol_port=listener.port)
541
+        listener.id = response['id']
556 542
         return listener
557 543
 
558 544
     def _find_listener(self, listener):
559 545
         lbaas = clients.get_loadbalancer_client()
560
-        response = lbaas.list_listeners(
546
+        response = lbaas.listeners(
561 547
             name=listener.name,
562 548
             project_id=listener.project_id,
563
-            loadbalancer_id=listener.loadbalancer_id,
549
+            load_balancer_id=listener.loadbalancer_id,
564 550
             protocol=listener.protocol,
565 551
             protocol_port=listener.port)
566 552
 
567 553
         try:
568
-            listener.id = response['listeners'][0]['id']
569
-        except (KeyError, IndexError):
554
+            os_listener = next(response)
555
+            listener.id = os_listener['id']
556
+        except (KeyError, StopIteration):
570 557
             return None
571 558
 
572 559
         return listener
@@ -575,49 +562,19 @@ class LBaaSv2Driver(base.LBaaSDriver):
575 562
         # TODO(ivc): make lb_algorithm configurable
576 563
         lb_algorithm = 'ROUND_ROBIN'
577 564
         lbaas = clients.get_loadbalancer_client()
578
-        try:
579
-            response = lbaas.create_lbaas_pool({'pool': {
580
-                'name': pool.name,
581
-                'project_id': pool.project_id,
582
-                'listener_id': pool.listener_id,
583
-                'loadbalancer_id': pool.loadbalancer_id,
584
-                'protocol': pool.protocol,
585
-                'lb_algorithm': lb_algorithm}})
586
-            pool.id = response['pool']['id']
587
-            return pool
588
-        except n_exc.StateInvalidClient:
589
-            (type_, value, tb) = sys.exc_info()
590
-            try:
591
-                self._cleanup_bogus_pool(lbaas, pool, lb_algorithm)
592
-            except Exception:
593
-                LOG.error('Pool creation traceback: %s',
594
-                          traceback.format_exception(type_, value, tb))
595
-                raise
596
-            else:
597
-                six.reraise(type_, value, tb)
598
-
599
-    def _cleanup_bogus_pool(self, lbaas, pool, lb_algorithm):
600
-        # REVISIT(ivc): LBaaSv2 creates pool object despite raising an
601
-        # exception. The created pool is not bound to listener, but
602
-        # it is bound to loadbalancer and will cause an error on
603
-        # 'release_loadbalancer'.
604
-        pools = lbaas.list_lbaas_pools(
605
-            name=pool.name, project_id=pool.project_id,
565
+        response = lbaas.create_pool(
566
+            name=pool.name,
567
+            project_id=pool.project_id,
568
+            listener_id=pool.listener_id,
606 569
             loadbalancer_id=pool.loadbalancer_id,
607
-            protocol=pool.protocol, lb_algorithm=lb_algorithm)
608
-        bogus_pool_ids = [p['id'] for p in pools.get('pools')
609
-                          if not p['listeners'] and pool.name == p['name']]
610
-        for pool_id in bogus_pool_ids:
611
-            try:
612
-                LOG.debug("Removing bogus pool %(id)s %(pool)s", {
613
-                    'id': pool_id, 'pool': pool})
614
-                lbaas.delete_lbaas_pool(pool_id)
615
-            except (n_exc.NotFound, n_exc.StateInvalidClient):
616
-                pass
570
+            protocol=pool.protocol,
571
+            lb_algorithm=lb_algorithm)
572
+        pool.id = response['id']
573
+        return pool
617 574
 
618 575
     def _find_pool(self, pool, by_listener=True):
619 576
         lbaas = clients.get_loadbalancer_client()
620
-        response = lbaas.list_lbaas_pools(
577
+        response = lbaas.pools(
621 578
             name=pool.name,
622 579
             project_id=pool.project_id,
623 580
             loadbalancer_id=pool.loadbalancer_id,
@@ -625,12 +582,10 @@ class LBaaSv2Driver(base.LBaaSDriver):
625 582
 
626 583
         try:
627 584
             if by_listener:
628
-                pools = [p for p in response['pools']
629
-                         if pool.listener_id
585
+                pools = [p for p in response if pool.listener_id
630 586
                          in {l['id'] for l in p['listeners']}]
631 587
             else:
632
-                pools = [p for p in response['pools']
633
-                         if pool.name == p['name']]
588
+                pools = [p for p in response if pool.name == p['name']]
634 589
 
635 590
             pool.id = pools[0]['id']
636 591
         except (KeyError, IndexError):
@@ -642,18 +597,19 @@ class LBaaSv2Driver(base.LBaaSDriver):
642 597
 
643 598
     def _create_member(self, member):
644 599
         lbaas = clients.get_loadbalancer_client()
645
-        response = lbaas.create_lbaas_member(member.pool_id, {'member': {
646
-            'name': member.name,
647
-            'project_id': member.project_id,
648
-            'subnet_id': member.subnet_id,
649
-            'address': str(member.ip),
650
-            'protocol_port': member.port}})
651
-        member.id = response['member']['id']
600
+        response = lbaas.create_member(
601
+            member.pool_id,
602
+            name=member.name,
603
+            project_id=member.project_id,
604
+            subnet_id=member.subnet_id,
605
+            address=str(member.ip),
606
+            protocol_port=member.port)
607
+        member.id = response['id']
652 608
         return member
653 609
 
654 610
     def _find_member(self, member):
655 611
         lbaas = clients.get_loadbalancer_client()
656
-        response = lbaas.list_lbaas_members(
612
+        response = lbaas.members(
657 613
             member.pool_id,
658 614
             name=member.name,
659 615
             project_id=member.project_id,
@@ -662,8 +618,8 @@ class LBaaSv2Driver(base.LBaaSDriver):
662 618
             protocol_port=member.port)
663 619
 
664 620
         try:
665
-            member.id = response['members'][0]['id']
666
-        except (KeyError, IndexError):
621
+            member.id = next(response)['id']
622
+        except (KeyError, StopIteration):
667 623
             return None
668 624
 
669 625
         return member
@@ -673,7 +629,9 @@ class LBaaSv2Driver(base.LBaaSDriver):
673 629
         try:
674 630
             result = create(obj)
675 631
             LOG.debug("Created %(obj)s", {'obj': result})
676
-        except (n_exc.Conflict, n_exc.InternalServerError):
632
+        except o_exc.HttpException as e:
633
+            if e.status_code not in (409, 500):
634
+                raise
677 635
             result = find(obj)
678 636
             if result:
679 637
                 LOG.debug("Found %(obj)s", {'obj': result})
@@ -688,7 +646,7 @@ class LBaaSv2Driver(base.LBaaSDriver):
688 646
                 result = self._ensure(obj, create, find)
689 647
                 if result:
690 648
                     return result
691
-            except n_exc.StateInvalidClient:
649
+            except o_exc.BadRequestException:
692 650
                 continue
693 651
 
694 652
         raise k_exc.ResourceNotReady(obj)
@@ -699,9 +657,9 @@ class LBaaSv2Driver(base.LBaaSDriver):
699 657
                 try:
700 658
                     delete(*args, **kwargs)
701 659
                     return
702
-                except (n_exc.Conflict, n_exc.StateInvalidClient):
660
+                except (o_exc.ConflictException, o_exc.BadRequestException):
703 661
                     self._wait_for_provisioning(loadbalancer, remaining)
704
-            except n_exc.NotFound:
662
+            except o_exc.ResourceNotFound:
705 663
                 return
706 664
 
707 665
         raise k_exc.ResourceNotReady(obj)
@@ -711,8 +669,8 @@ class LBaaSv2Driver(base.LBaaSDriver):
711 669
         lbaas = clients.get_loadbalancer_client()
712 670
 
713 671
         for remaining in self._provisioning_timer(timeout, interval):
714
-            response = lbaas.show_loadbalancer(loadbalancer.id)
715
-            status = response['loadbalancer']['provisioning_status']
672
+            response = lbaas.get_load_balancer(loadbalancer.id)
673
+            status = response['provisioning_status']
716 674
             if status == 'ACTIVE':
717 675
                 LOG.debug("Provisioning complete for %(lb)s", {
718 676
                     'lb': loadbalancer})
@@ -731,8 +689,8 @@ class LBaaSv2Driver(base.LBaaSDriver):
731 689
 
732 690
         for remaining in self._provisioning_timer(timeout, interval):
733 691
             try:
734
-                lbaas.show_loadbalancer(loadbalancer.id)
735
-            except n_exc.NotFound:
692
+                lbaas.get_load_balancer(loadbalancer.id)
693
+            except o_exc.ResourceNotFound:
736 694
                 return
737 695
 
738 696
     def _provisioning_timer(self, timeout,
@@ -777,20 +735,21 @@ class LBaaSv2Driver(base.LBaaSDriver):
777 735
 
778 736
     def get_lb_by_uuid(self, lb_uuid):
779 737
         lbaas = clients.get_loadbalancer_client()
780
-        response = lbaas.show_loadbalancer(lb_uuid)
781 738
         try:
782
-            return obj_lbaas.LBaaSLoadBalancer(
783
-                id=response['loadbalancer']['id'],
784
-                port_id=response['loadbalancer']['vip_port_id'],
785
-                name=response['loadbalancer']['name'],
786
-                project_id=response['loadbalancer']['project_id'],
787
-                subnet_id=response['loadbalancer']['vip_subnet_id'],
788
-                ip=response['loadbalancer']['vip_address'],
789
-                security_groups=None,
790
-                provider=response['loadbalancer']['provider'])
791
-        except (KeyError, IndexError):
739
+            response = lbaas.get_load_balancer(lb_uuid)
740
+        except o_exc.ResourceNotFound:
792 741
             LOG.debug("Couldn't find loadbalancer with uuid=%s", lb_uuid)
793
-        return None
742
+            return None
743
+
744
+        return obj_lbaas.LBaaSLoadBalancer(
745
+            id=response['id'],
746
+            port_id=response['vip_port_id'],
747
+            name=response['name'],
748
+            project_id=response['project_id'],
749
+            subnet_id=response['vip_subnet_id'],
750
+            ip=response['vip_address'],
751
+            security_groups=None,
752
+            provider=response['provider'])
794 753
 
795 754
     def get_pool_by_name(self, pool_name, project_id):
796 755
         lbaas = clients.get_loadbalancer_client()
@@ -799,9 +758,8 @@ class LBaaSv2Driver(base.LBaaSDriver):
799 758
         # get_loadbalancer_pool_name function, which means that pool's name
800 759
         # is unique
801 760
 
802
-        pools_list = lbaas.list_lbaas_pools(
803
-            project_id=project_id)
804
-        for entry in pools_list['pools']:
761
+        pools = lbaas.pools(project_id=project_id)
762
+        for entry in pools:
805 763
             if not entry:
806 764
                 continue
807 765
             if entry['name'] == pool_name:
@@ -830,30 +788,30 @@ class LBaaSv2Driver(base.LBaaSDriver):
830 788
     def release_l7_policy(self, loadbalancer, l7_policy):
831 789
         lbaas = clients.get_loadbalancer_client()
832 790
         self._release(
833
-            loadbalancer, l7_policy, lbaas.delete_lbaas_l7policy,
791
+            loadbalancer, l7_policy, lbaas.delete_l7_policy,
834 792
             l7_policy.id)
835 793
 
836 794
     def _create_l7_policy(self, l7_policy):
837 795
         lbaas = clients.get_loadbalancer_client()
838
-        response = lbaas.create_lbaas_l7policy({'l7policy': {
839
-            'action': _L7_POLICY_ACT_REDIRECT_TO_POOL,
840
-            'listener_id': l7_policy.listener_id,
841
-            'name': l7_policy.name,
842
-            'project_id': l7_policy.project_id,
843
-            'redirect_pool_id': l7_policy.redirect_pool_id}})
844
-        l7_policy.id = response['l7policy']['id']
796
+        response = lbaas.create_l7_policy(
797
+            action=_L7_POLICY_ACT_REDIRECT_TO_POOL,
798
+            listener_id=l7_policy.listener_id,
799
+            name=l7_policy.name,
800
+            project_id=l7_policy.project_id,
801
+            redirect_pool_id=l7_policy.redirect_pool_id)
802
+        l7_policy.id = response['id']
845 803
         return l7_policy
846 804
 
847 805
     def _find_l7_policy(self, l7_policy):
848 806
         lbaas = clients.get_loadbalancer_client()
849
-        response = lbaas.list_lbaas_l7policies(
807
+        response = lbaas.l7_policies(
850 808
             name=l7_policy.name,
851 809
             project_id=l7_policy.project_id,
852 810
             redirect_pool_id=l7_policy.redirect_pool_id,
853 811
             listener_id=l7_policy.listener_id)
854 812
         try:
855
-            l7_policy.id = response['l7policies'][0]['id']
856
-        except (KeyError, IndexError):
813
+            l7_policy.id = next(response)['id']
814
+        except (KeyError, StopIteration):
857 815
             return None
858 816
         return l7_policy
859 817
 
@@ -869,49 +827,47 @@ class LBaaSv2Driver(base.LBaaSDriver):
869 827
 
870 828
     def _create_l7_rule(self, l7_rule):
871 829
         lbaas = clients.get_loadbalancer_client()
872
-        response = lbaas.create_lbaas_l7rule(
830
+        response = lbaas.create_l7_rule(
873 831
             l7_rule.l7policy_id,
874
-            {'rule': {'compare_type': l7_rule.compare_type,
875
-                      'type': l7_rule.type,
876
-                      'value': l7_rule.value}})
877
-        l7_rule.id = response['rule']['id']
832
+            compare_type=l7_rule.compare_type,
833
+            type=l7_rule.type,
834
+            value=l7_rule.value)
835
+        l7_rule.id = response['id']
878 836
         return l7_rule
879 837
 
880 838
     def _find_l7_rule(self, l7_rule):
881 839
         lbaas = clients.get_loadbalancer_client()
882
-        response = lbaas.list_lbaas_l7rules(
840
+        response = lbaas.l7_rules(
883 841
             l7_rule.l7policy_id,
884 842
             type=l7_rule.type,
885 843
             value=l7_rule.value,
886 844
             compare_type=l7_rule.compare_type)
887 845
         try:
888
-            l7_rule.id = response['rules'][0]['id']
889
-        except (KeyError, IndexError):
846
+            l7_rule.id = next(response)['id']
847
+        except (KeyError, StopIteration):
890 848
             return None
891 849
         return l7_rule
892 850
 
893 851
     def release_l7_rule(self, loadbalancer, l7_rule):
894 852
         lbaas = clients.get_loadbalancer_client()
895 853
         self._release(
896
-            loadbalancer, l7_rule, lbaas.delete_lbaas_l7rule,
854
+            loadbalancer, l7_rule, lbaas.delete_l7_rule,
897 855
             l7_rule.id, l7_rule.l7policy_id)
898 856
 
899 857
     def update_l7_rule(self, l7_rule, new_value):
900 858
         lbaas = clients.get_loadbalancer_client()
901 859
         try:
902
-            lbaas.update_lbaas_l7rule(
860
+            lbaas.update_l7_rule(
903 861
                 l7_rule.id, l7_rule.l7policy_id,
904
-                {'rule': {'value': new_value}})
905
-
906
-        except n_exc.NeutronClientException:
862
+                value=new_value)
863
+        except o_exc.SDKException:
907 864
             LOG.exception("Failed to update l7_rule- id=%s ", l7_rule.id)
908 865
             raise
909 866
 
910 867
     def is_pool_used_by_other_l7policies(self, l7policy, pool):
911 868
         lbaas = clients.get_loadbalancer_client()
912
-        l7policy_list = lbaas.list_lbaas_l7policies(
913
-            project_id=l7policy.project_id)
914
-        for entry in l7policy_list['l7policies']:
869
+        l7policy_list = lbaas.l7_policies(project_id=l7policy.project_id)
870
+        for entry in l7policy_list:
915 871
             if not entry:
916 872
                 continue
917 873
             if (entry['redirect_pool_id'] == pool.id and

+ 5
- 10
kuryr_kubernetes/controller/handlers/lbaas.py View File

@@ -250,16 +250,11 @@ class LoadBalancerHandler(k8s_base.ResourceEventHandler):
250 250
         if not lbaas_state:
251 251
             return
252 252
         # NOTE(ivc): deleting pool deletes its members
253
-        if self._drv_lbaas.cascading_capable:
254
-            self._drv_lbaas.release_loadbalancer(
255
-                loadbalancer=lbaas_state.loadbalancer)
256
-            if lbaas_state.service_pub_ip_info:
257
-                self._drv_service_pub_ip.release_pub_ip(
258
-                    lbaas_state.service_pub_ip_info)
259
-        else:
260
-            lbaas_state.members = []
261
-            self._sync_lbaas_members(endpoints, lbaas_state,
262
-                                     obj_lbaas.LBaaSServiceSpec())
253
+        self._drv_lbaas.release_loadbalancer(
254
+            loadbalancer=lbaas_state.loadbalancer)
255
+        if lbaas_state.service_pub_ip_info:
256
+            self._drv_service_pub_ip.release_pub_ip(
257
+                lbaas_state.service_pub_ip_info)
263 258
 
264 259
     def _should_ignore(self, endpoints, lbaas_spec):
265 260
         return not(lbaas_spec and

+ 143
- 166
kuryr_kubernetes/tests/unit/controller/drivers/test_lbaasv2.py View File

@@ -16,6 +16,7 @@
16 16
 import mock
17 17
 
18 18
 from neutronclient.common import exceptions as n_exc
19
+from openstack import exceptions as o_exc
19 20
 
20 21
 from kuryr_kubernetes.controller.drivers import lbaasv2 as d_lbaasv2
21 22
 from kuryr_kubernetes import exceptions as k_exc
@@ -68,24 +69,9 @@ class TestLBaaSv2Driver(test_base.TestCase):
68 69
                           m_driver, name, project_id, subnet_id, ip,
69 70
                           sg_ids, 'ClusterIP')
70 71
 
71
-    def test_release_loadbalancer(self):
72
-        self.useFixture(k_fix.MockNeutronClient()).client
73
-        lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
74
-        lbaas.cascading_capable = False
75
-        cls = d_lbaasv2.LBaaSv2Driver
76
-        m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
77
-        loadbalancer = mock.Mock()
78
-
79
-        cls.release_loadbalancer(m_driver, loadbalancer)
80
-
81
-        m_driver._release.assert_called_once_with(loadbalancer, loadbalancer,
82
-                                                  lbaas.delete_loadbalancer,
83
-                                                  loadbalancer.id)
84
-
85 72
     def test_cascade_release_loadbalancer(self):
86 73
         self.useFixture(k_fix.MockNeutronClient()).client
87 74
         lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
88
-        lbaas.cascading_capable = True
89 75
         lbaas.lbaas_loadbalancer_path = "boo %s"
90 76
         cls = d_lbaasv2.LBaaSv2Driver
91 77
         m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
@@ -94,9 +80,8 @@ class TestLBaaSv2Driver(test_base.TestCase):
94 80
         cls.release_loadbalancer(m_driver, loadbalancer)
95 81
 
96 82
         m_driver._release.assert_called_once_with(
97
-            loadbalancer, loadbalancer, lbaas.delete,
98
-            lbaas.lbaas_loadbalancer_path % loadbalancer.id,
99
-            params={'cascade': True})
83
+            loadbalancer, loadbalancer, lbaas.delete_load_balancer,
84
+            loadbalancer.id, cascade=True)
100 85
 
101 86
     def _test_ensure_listener(self):
102 87
         cls = d_lbaasv2.LBaaSv2Driver
@@ -146,7 +131,7 @@ class TestLBaaSv2Driver(test_base.TestCase):
146 131
         loadbalancer = obj_lbaas.LBaaSLoadBalancer(
147 132
             id=loadbalancer_id, name=name, project_id=project_id,
148 133
             subnet_id=subnet_id, ip=ip, provider=provider)
149
-        m_driver._ensure_provisioned.side_effect = n_exc.BadRequest
134
+        m_driver._ensure_provisioned.side_effect = o_exc.BadRequestException
150 135
 
151 136
         resp = cls.ensure_listener(m_driver, loadbalancer,
152 137
                                    protocol, port)
@@ -205,7 +190,7 @@ class TestLBaaSv2Driver(test_base.TestCase):
205 190
         cls.release_pool(m_driver, loadbalancer, pool)
206 191
 
207 192
         m_driver._release.assert_called_once_with(loadbalancer, pool,
208
-                                                  lbaas.delete_lbaas_pool,
193
+                                                  lbaas.delete_pool,
209 194
                                                   pool.id)
210 195
 
211 196
     def test_ensure_member(self):
@@ -251,7 +236,7 @@ class TestLBaaSv2Driver(test_base.TestCase):
251 236
         cls.release_member(m_driver, loadbalancer, member)
252 237
 
253 238
         m_driver._release.assert_called_once_with(loadbalancer, member,
254
-                                                  lbaas.delete_lbaas_member,
239
+                                                  lbaas.delete_member,
255 240
                                                   member.id, member.pool_id)
256 241
 
257 242
     def test_create_loadbalancer(self):
@@ -263,18 +248,18 @@ class TestLBaaSv2Driver(test_base.TestCase):
263 248
             subnet_id='D3FA400A-F543-4B91-9CD3-047AF0CE42D1',
264 249
             security_groups=[])
265 250
         loadbalancer_id = '00EE9E11-91C2-41CF-8FD4-7970579E5C4C'
266
-        req = {'loadbalancer': {
251
+        req = {
267 252
             'name': loadbalancer.name,
268 253
             'project_id': loadbalancer.project_id,
269 254
             'vip_address': str(loadbalancer.ip),
270 255
             'vip_subnet_id': loadbalancer.subnet_id,
271
-        }}
272
-        resp = {'loadbalancer': {'id': loadbalancer_id, 'provider': 'haproxy'}}
273
-        lbaas.create_loadbalancer.return_value = resp
256
+        }
257
+        resp = {'id': loadbalancer_id, 'provider': 'haproxy'}
258
+        lbaas.create_load_balancer.return_value = resp
274 259
         m_driver._get_vip_port.return_value = {'id': mock.sentinel.port_id}
275 260
 
276 261
         ret = cls._create_loadbalancer(m_driver, loadbalancer)
277
-        lbaas.create_loadbalancer.assert_called_once_with(req)
262
+        lbaas.create_load_balancer.assert_called_once_with(**req)
278 263
         for attr in loadbalancer.obj_fields:
279 264
             self.assertEqual(getattr(loadbalancer, attr),
280 265
                              getattr(ret, attr))
@@ -290,19 +275,19 @@ class TestLBaaSv2Driver(test_base.TestCase):
290 275
             security_groups=[],
291 276
             provider='amphora')
292 277
         loadbalancer_id = '00EE9E11-91C2-41CF-8FD4-7970579E5C4C'
293
-        req = {'loadbalancer': {
278
+        req = {
294 279
             'name': loadbalancer.name,
295 280
             'project_id': loadbalancer.project_id,
296 281
             'vip_address': str(loadbalancer.ip),
297 282
             'vip_subnet_id': loadbalancer.subnet_id,
298 283
             'provider': loadbalancer.provider,
299
-        }}
300
-        resp = {'loadbalancer': {'id': loadbalancer_id, 'provider': 'amphora'}}
301
-        lbaas.create_loadbalancer.return_value = resp
284
+        }
285
+        resp = {'id': loadbalancer_id, 'provider': 'amphora'}
286
+        lbaas.create_load_balancer.return_value = resp
302 287
         m_driver._get_vip_port.return_value = {'id': mock.sentinel.port_id}
303 288
 
304 289
         ret = cls._create_loadbalancer(m_driver, loadbalancer)
305
-        lbaas.create_loadbalancer.assert_called_once_with(req)
290
+        lbaas.create_load_balancer.assert_called_once_with(**req)
306 291
         for attr in loadbalancer.obj_fields:
307 292
             self.assertEqual(getattr(loadbalancer, attr),
308 293
                              getattr(ret, attr))
@@ -318,19 +303,19 @@ class TestLBaaSv2Driver(test_base.TestCase):
318 303
             security_groups=[],
319 304
             provider='amphora')
320 305
         loadbalancer_id = '00EE9E11-91C2-41CF-8FD4-7970579E5C4C'
321
-        req = {'loadbalancer': {
306
+        req = {
322 307
             'name': loadbalancer.name,
323 308
             'project_id': loadbalancer.project_id,
324 309
             'vip_address': str(loadbalancer.ip),
325 310
             'vip_subnet_id': loadbalancer.subnet_id,
326 311
             'provider': loadbalancer.provider,
327
-        }}
328
-        resp = {'loadbalancer': {'id': loadbalancer_id, 'provider': 'haproxy'}}
329
-        lbaas.create_loadbalancer.return_value = resp
312
+        }
313
+        resp = {'id': loadbalancer_id, 'provider': 'haproxy'}
314
+        lbaas.create_load_balancer.return_value = resp
330 315
         m_driver._get_vip_port.return_value = {'id': mock.sentinel.port_id}
331 316
 
332 317
         ret = cls._create_loadbalancer(m_driver, loadbalancer)
333
-        lbaas.create_loadbalancer.assert_called_once_with(req)
318
+        lbaas.create_load_balancer.assert_called_once_with(**req)
334 319
         self.assertIsNone(ret)
335 320
 
336 321
     def test_find_loadbalancer(self):
@@ -342,14 +327,14 @@ class TestLBaaSv2Driver(test_base.TestCase):
342 327
             subnet_id='D3FA400A-F543-4B91-9CD3-047AF0CE42D1',
343 328
             provider='haproxy', security_groups=[])
344 329
         loadbalancer_id = '00EE9E11-91C2-41CF-8FD4-7970579E5C4C'
345
-        resp = {'loadbalancers': [{'id': loadbalancer_id,
346
-                                   'provider': 'haproxy',
347
-                                   'provisioning_status': 'ACTIVE'}]}
348
-        lbaas.list_loadbalancers.return_value = resp
330
+        resp = iter([{'id': loadbalancer_id,
331
+                      'provider': 'haproxy',
332
+                      'provisioning_status': 'ACTIVE'}])
333
+        lbaas.load_balancers.return_value = resp
349 334
         m_driver._get_vip_port.return_value = {'id': mock.sentinel.port_id}
350 335
 
351 336
         ret = cls._find_loadbalancer(m_driver, loadbalancer)
352
-        lbaas.list_loadbalancers.assert_called_once_with(
337
+        lbaas.load_balancers.assert_called_once_with(
353 338
             name=loadbalancer.name,
354 339
             project_id=loadbalancer.project_id,
355 340
             vip_address=str(loadbalancer.ip),
@@ -367,11 +352,11 @@ class TestLBaaSv2Driver(test_base.TestCase):
367 352
         loadbalancer = obj_lbaas.LBaaSLoadBalancer(
368 353
             name='TEST_NAME', project_id='TEST_PROJECT', ip='1.2.3.4',
369 354
             subnet_id='D3FA400A-F543-4B91-9CD3-047AF0CE42D1')
370
-        resp = {'loadbalancers': []}
371
-        lbaas.list_loadbalancers.return_value = resp
355
+        resp = iter([])
356
+        lbaas.load_balancers.return_value = resp
372 357
 
373 358
         ret = cls._find_loadbalancer(m_driver, loadbalancer)
374
-        lbaas.list_loadbalancers.assert_called_once_with(
359
+        lbaas.load_balancers.assert_called_once_with(
375 360
             name=loadbalancer.name,
376 361
             project_id=loadbalancer.project_id,
377 362
             vip_address=str(loadbalancer.ip),
@@ -387,14 +372,14 @@ class TestLBaaSv2Driver(test_base.TestCase):
387 372
             name='TEST_NAME', project_id='TEST_PROJECT', ip='1.2.3.4',
388 373
             subnet_id='D3FA400A-F543-4B91-9CD3-047AF0CE42D1')
389 374
         loadbalancer_id = '00EE9E11-91C2-41CF-8FD4-7970579E5C4C'
390
-        resp = {'loadbalancers': [{'id': loadbalancer_id,
391
-                                   'provider': 'haproxy',
392
-                                   'provisioning_status': 'ERROR'}]}
393
-        lbaas.list_loadbalancers.return_value = resp
375
+        resp = iter([{'id': loadbalancer_id,
376
+                      'provider': 'haproxy',
377
+                      'provisioning_status': 'ERROR'}])
378
+        lbaas.load_balancers.return_value = resp
394 379
         m_driver._get_vip_port.return_value = {'id': mock.sentinel.port_id}
395 380
 
396 381
         ret = cls._find_loadbalancer(m_driver, loadbalancer)
397
-        lbaas.list_loadbalancers.assert_called_once_with(
382
+        lbaas.load_balancers.assert_called_once_with(
398 383
             name=loadbalancer.name,
399 384
             project_id=loadbalancer.project_id,
400 385
             vip_address=str(loadbalancer.ip),
@@ -410,17 +395,17 @@ class TestLBaaSv2Driver(test_base.TestCase):
410 395
             name='TEST_NAME', project_id='TEST_PROJECT', protocol='TCP',
411 396
             port=1234, loadbalancer_id='00EE9E11-91C2-41CF-8FD4-7970579E5C4C')
412 397
         listener_id = 'A57B7771-6050-4CA8-A63C-443493EC98AB'
413
-        req = {'listener': {
398
+        req = {
414 399
             'name': listener.name,
415 400
             'project_id': listener.project_id,
416
-            'loadbalancer_id': listener.loadbalancer_id,
401
+            'load_balancer_id': listener.loadbalancer_id,
417 402
             'protocol': listener.protocol,
418
-            'protocol_port': listener.port}}
419
-        resp = {'listener': {'id': listener_id}}
403
+            'protocol_port': listener.port}
404
+        resp = {'id': listener_id}
420 405
         lbaas.create_listener.return_value = resp
421 406
 
422 407
         ret = cls._create_listener(m_driver, listener)
423
-        lbaas.create_listener.assert_called_once_with(req)
408
+        lbaas.create_listener.assert_called_once_with(**req)
424 409
         for attr in listener.obj_fields:
425 410
             self.assertEqual(getattr(listener, attr),
426 411
                              getattr(ret, attr))
@@ -434,14 +419,13 @@ class TestLBaaSv2Driver(test_base.TestCase):
434 419
             name='TEST_NAME', project_id='TEST_PROJECT', protocol='TCP',
435 420
             port=1234, loadbalancer_id='00EE9E11-91C2-41CF-8FD4-7970579E5C4C')
436 421
         listener_id = 'A57B7771-6050-4CA8-A63C-443493EC98AB'
437
-        resp = {'listeners': [{'id': listener_id}]}
438
-        lbaas.list_listeners.return_value = resp
422
+        lbaas.listeners.return_value = iter([{'id': listener_id}])
439 423
 
440 424
         ret = cls._find_listener(m_driver, listener)
441
-        lbaas.list_listeners.assert_called_once_with(
425
+        lbaas.listeners.assert_called_once_with(
442 426
             name=listener.name,
443 427
             project_id=listener.project_id,
444
-            loadbalancer_id=listener.loadbalancer_id,
428
+            load_balancer_id=listener.loadbalancer_id,
445 429
             protocol=listener.protocol,
446 430
             protocol_port=listener.port)
447 431
         for attr in listener.obj_fields:
@@ -456,14 +440,14 @@ class TestLBaaSv2Driver(test_base.TestCase):
456 440
         listener = obj_lbaas.LBaaSListener(
457 441
             name='TEST_NAME', project_id='TEST_PROJECT', protocol='TCP',
458 442
             port=1234, loadbalancer_id='00EE9E11-91C2-41CF-8FD4-7970579E5C4C')
459
-        resp = {'listeners': []}
460
-        lbaas.list_listeners.return_value = resp
443
+        resp = iter([])
444
+        lbaas.listeners.return_value = resp
461 445
 
462 446
         ret = cls._find_listener(m_driver, listener)
463
-        lbaas.list_listeners.assert_called_once_with(
447
+        lbaas.listeners.assert_called_once_with(
464 448
             name=listener.name,
465 449
             project_id=listener.project_id,
466
-            loadbalancer_id=listener.loadbalancer_id,
450
+            load_balancer_id=listener.loadbalancer_id,
467 451
             protocol=listener.protocol,
468 452
             protocol_port=listener.port)
469 453
         self.assertIsNone(ret)
@@ -478,18 +462,18 @@ class TestLBaaSv2Driver(test_base.TestCase):
478 462
             listener_id='A57B7771-6050-4CA8-A63C-443493EC98AB',
479 463
             loadbalancer_id='00EE9E11-91C2-41CF-8FD4-7970579E5C4C')
480 464
         pool_id = 'D4F35594-27EB-4F4C-930C-31DD40F53B77'
481
-        req = {'pool': {
465
+        req = {
482 466
             'name': pool.name,
483 467
             'project_id': pool.project_id,
484 468
             'listener_id': pool.listener_id,
485 469
             'loadbalancer_id': pool.loadbalancer_id,
486 470
             'protocol': pool.protocol,
487
-            'lb_algorithm': lb_algorithm}}
488
-        resp = {'pool': {'id': pool_id}}
489
-        lbaas.create_lbaas_pool.return_value = resp
471
+            'lb_algorithm': lb_algorithm}
472
+        resp = {'id': pool_id}
473
+        lbaas.create_pool.return_value = resp
490 474
 
491 475
         ret = cls._create_pool(m_driver, pool)
492
-        lbaas.create_lbaas_pool.assert_called_once_with(req)
476
+        lbaas.create_pool.assert_called_once_with(**req)
493 477
         for attr in pool.obj_fields:
494 478
             self.assertEqual(getattr(pool, attr),
495 479
                              getattr(ret, attr))
@@ -504,24 +488,18 @@ class TestLBaaSv2Driver(test_base.TestCase):
504 488
             name='TEST_NAME', project_id='TEST_PROJECT', protocol='TCP',
505 489
             listener_id='A57B7771-6050-4CA8-A63C-443493EC98AB',
506 490
             loadbalancer_id='00EE9E11-91C2-41CF-8FD4-7970579E5C4C')
507
-        req = {'pool': {
491
+        req = {
508 492
             'name': pool.name,
509 493
             'project_id': pool.project_id,
510 494
             'listener_id': pool.listener_id,
511 495
             'loadbalancer_id': pool.loadbalancer_id,
512 496
             'protocol': pool.protocol,
513
-            'lb_algorithm': lb_algorithm}}
514
-        lbaas.create_lbaas_pool.side_effect = n_exc.StateInvalidClient
497
+            'lb_algorithm': lb_algorithm}
498
+        lbaas.create_pool.side_effect = n_exc.StateInvalidClient
515 499
 
516 500
         self.assertRaises(n_exc.StateInvalidClient, cls._create_pool, m_driver,
517 501
                           pool)
518
-        lbaas.create_lbaas_pool.assert_called_once_with(req)
519
-        m_driver._cleanup_bogus_pool.assert_called_once_with(lbaas, pool,
520
-                                                             lb_algorithm)
521
-
522
-    def test_cleanup_bogus_pool(self):
523
-        # TODO(ivc): add unit test or get rid of _cleanup_bogus_pool
524
-        self.skipTest("not implemented")
502
+        lbaas.create_pool.assert_called_once_with(**req)
525 503
 
526 504
     def test_find_pool_by_listener(self):
527 505
         lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
@@ -532,12 +510,12 @@ class TestLBaaSv2Driver(test_base.TestCase):
532 510
             listener_id='A57B7771-6050-4CA8-A63C-443493EC98AB',
533 511
             loadbalancer_id='00EE9E11-91C2-41CF-8FD4-7970579E5C4C')
534 512
         pool_id = 'D4F35594-27EB-4F4C-930C-31DD40F53B77'
535
-        resp = {'pools': [{'id': pool_id,
536
-                           'listeners': [{'id': pool.listener_id}]}]}
537
-        lbaas.list_lbaas_pools.return_value = resp
513
+        resp = [{'id': pool_id,
514
+                 'listeners': [{'id': pool.listener_id}]}]
515
+        lbaas.pools.return_value = resp
538 516
 
539 517
         ret = cls._find_pool(m_driver, pool)
540
-        lbaas.list_lbaas_pools.assert_called_once_with(
518
+        lbaas.pools.assert_called_once_with(
541 519
             name=pool.name,
542 520
             project_id=pool.project_id,
543 521
             loadbalancer_id=pool.loadbalancer_id,
@@ -555,11 +533,11 @@ class TestLBaaSv2Driver(test_base.TestCase):
555 533
             name='TEST_NAME', project_id='TEST_PROJECT', protocol='TCP',
556 534
             listener_id='A57B7771-6050-4CA8-A63C-443493EC98AB',
557 535
             loadbalancer_id='00EE9E11-91C2-41CF-8FD4-7970579E5C4C')
558
-        resp = {'pools': []}
559
-        lbaas.list_lbaas_pools.return_value = resp
536
+        resp = []
537
+        lbaas.pools.return_value = resp
560 538
 
561 539
         ret = cls._find_pool(m_driver, pool)
562
-        lbaas.list_lbaas_pools.assert_called_once_with(
540
+        lbaas.pools.assert_called_once_with(
563 541
             name=pool.name,
564 542
             project_id=pool.project_id,
565 543
             loadbalancer_id=pool.loadbalancer_id,
@@ -575,18 +553,18 @@ class TestLBaaSv2Driver(test_base.TestCase):
575 553
             port=1234, subnet_id='D3FA400A-F543-4B91-9CD3-047AF0CE42D1',
576 554
             pool_id='D4F35594-27EB-4F4C-930C-31DD40F53B77')
577 555
         member_id = '3A70CEC0-392D-4BC1-A27C-06E63A0FD54F'
578
-        req = {'member': {
556
+        req = {
579 557
             'name': member.name,
580 558
             'project_id': member.project_id,
581 559
             'subnet_id': member.subnet_id,
582 560
             'address': str(member.ip),
583
-            'protocol_port': member.port}}
584
-        resp = {'member': {'id': member_id}}
585
-        lbaas.create_lbaas_member.return_value = resp
561
+            'protocol_port': member.port}
562
+        resp = {'id': member_id}
563
+        lbaas.create_member.return_value = resp
586 564
 
587 565
         ret = cls._create_member(m_driver, member)
588
-        lbaas.create_lbaas_member.assert_called_once_with(
589
-            member.pool_id, req)
566
+        lbaas.create_member.assert_called_once_with(
567
+            member.pool_id, **req)
590 568
         for attr in member.obj_fields:
591 569
             self.assertEqual(getattr(member, attr),
592 570
                              getattr(ret, attr))
@@ -601,11 +579,11 @@ class TestLBaaSv2Driver(test_base.TestCase):
601 579
             port=1234, subnet_id='D3FA400A-F543-4B91-9CD3-047AF0CE42D1',
602 580
             pool_id='D4F35594-27EB-4F4C-930C-31DD40F53B77')
603 581
         member_id = '3A70CEC0-392D-4BC1-A27C-06E63A0FD54F'
604
-        resp = {'members': [{'id': member_id}]}
605
-        lbaas.list_lbaas_members.return_value = resp
582
+        resp = iter([{'id': member_id}])
583
+        lbaas.members.return_value = resp
606 584
 
607 585
         ret = cls._find_member(m_driver, member)
608
-        lbaas.list_lbaas_members.assert_called_once_with(
586
+        lbaas.members.assert_called_once_with(
609 587
             member.pool_id,
610 588
             name=member.name,
611 589
             project_id=member.project_id,
@@ -625,11 +603,11 @@ class TestLBaaSv2Driver(test_base.TestCase):
625 603
             name='TEST_NAME', project_id='TEST_PROJECT', ip='1.2.3.4',
626 604
             port=1234, subnet_id='D3FA400A-F543-4B91-9CD3-047AF0CE42D1',
627 605
             pool_id='D4F35594-27EB-4F4C-930C-31DD40F53B77')
628
-        resp = {'members': []}
629
-        lbaas.list_lbaas_members.return_value = resp
606
+        resp = iter([])
607
+        lbaas.members.return_value = resp
630 608
 
631 609
         ret = cls._find_member(m_driver, member)
632
-        lbaas.list_lbaas_members.assert_called_once_with(
610
+        lbaas.members.assert_called_once_with(
633 611
             member.pool_id,
634 612
             name=member.name,
635 613
             project_id=member.project_id,
@@ -667,10 +645,12 @@ class TestLBaaSv2Driver(test_base.TestCase):
667 645
         self.assertEqual(expected_result, ret)
668 646
 
669 647
     def test_ensure_with_conflict(self):
670
-        self._verify_ensure_with_exception(n_exc.Conflict)
648
+        self._verify_ensure_with_exception(
649
+            o_exc.ConflictException(http_status=409))
671 650
 
672 651
     def test_ensure_with_internalservererror(self):
673
-        self._verify_ensure_with_exception(n_exc.InternalServerError)
652
+        self._verify_ensure_with_exception(
653
+            o_exc.HttpException(http_status=500))
674 654
 
675 655
     def test_request(self):
676 656
         cls = d_lbaasv2.LBaaSv2Driver
@@ -682,7 +662,7 @@ class TestLBaaSv2Driver(test_base.TestCase):
682 662
         expected_result = mock.sentinel.expected_result
683 663
         timer = [mock.sentinel.t0, mock.sentinel.t1]
684 664
         m_driver._provisioning_timer.return_value = timer
685
-        m_driver._ensure.side_effect = [n_exc.StateInvalidClient,
665
+        m_driver._ensure.side_effect = [o_exc.BadRequestException,
686 666
                                         expected_result]
687 667
 
688 668
         ret = cls._ensure_provisioned(m_driver, loadbalancer, obj, create,
@@ -738,7 +718,7 @@ class TestLBaaSv2Driver(test_base.TestCase):
738 718
         m_delete = mock.Mock()
739 719
         timer = [mock.sentinel.t0, mock.sentinel.t1]
740 720
         m_driver._provisioning_timer.return_value = timer
741
-        m_delete.side_effect = [n_exc.StateInvalidClient, None]
721
+        m_delete.side_effect = [o_exc.BadRequestException, None]
742 722
 
743 723
         cls._release(m_driver, loadbalancer, obj, m_delete)
744 724
 
@@ -754,7 +734,7 @@ class TestLBaaSv2Driver(test_base.TestCase):
754 734
         m_delete = mock.Mock()
755 735
         timer = [mock.sentinel.t0, mock.sentinel.t1]
756 736
         m_driver._provisioning_timer.return_value = timer
757
-        m_delete.side_effect = n_exc.NotFound
737
+        m_delete.side_effect = o_exc.NotFoundException
758 738
 
759 739
         cls._release(m_driver, loadbalancer, obj, m_delete)
760 740
 
@@ -769,7 +749,7 @@ class TestLBaaSv2Driver(test_base.TestCase):
769 749
         m_delete = mock.Mock()
770 750
         timer = [mock.sentinel.t0, mock.sentinel.t1]
771 751
         m_driver._provisioning_timer.return_value = timer
772
-        m_delete.side_effect = n_exc.StateInvalidClient
752
+        m_delete.side_effect = o_exc.ConflictException
773 753
 
774 754
         self.assertRaises(k_exc.ResourceNotReady, cls._release, m_driver,
775 755
                           loadbalancer, obj, m_delete)
@@ -787,12 +767,12 @@ class TestLBaaSv2Driver(test_base.TestCase):
787 767
         timeout = mock.sentinel.timeout
788 768
         timer = [mock.sentinel.t0, mock.sentinel.t1]
789 769
         m_driver._provisioning_timer.return_value = timer
790
-        resp = {'loadbalancer': {'provisioning_status': 'ACTIVE'}}
791
-        lbaas.show_loadbalancer.return_value = resp
770
+        resp = {'provisioning_status': 'ACTIVE'}
771
+        lbaas.get_load_balancer.return_value = resp
792 772
 
793 773
         cls._wait_for_provisioning(m_driver, loadbalancer, timeout)
794 774
 
795
-        lbaas.show_loadbalancer.assert_called_once_with(loadbalancer.id)
775
+        lbaas.get_load_balancer.assert_called_once_with(loadbalancer.id)
796 776
 
797 777
     def test_wait_for_provisioning_not_ready(self):
798 778
         lbaas = self.useFixture(k_fix.MockLBaaSClient()).client
@@ -802,13 +782,13 @@ class TestLBaaSv2Driver(test_base.TestCase):
802 782
         timeout = mock.sentinel.timeout
803 783
         timer = [mock.sentinel.t0, mock.sentinel.t1]
804 784
         m_driver._provisioning_timer.return_value = timer
805
-        resp = {'loadbalancer': {'provisioning_status': 'NOT_ACTIVE'}}
806
-        lbaas.show_loadbalancer.return_value = resp
785
+        resp = {'provisioning_status': 'NOT_ACTIVE'}
786
+        lbaas.get_load_balancer.return_value = resp
807 787
 
808 788
         self.assertRaises(k_exc.ResourceNotReady, cls._wait_for_provisioning,
809 789
                           m_driver, loadbalancer, timeout)
810 790
 
811
-        self.assertEqual(len(timer), lbaas.show_loadbalancer.call_count)
791
+        self.assertEqual(len(timer), lbaas.get_load_balancer.call_count)
812 792
 
813 793
     def test_provisioning_timer(self):
814 794
         # REVISIT(ivc): add test if _provisioning_timer is to stay
@@ -820,7 +800,7 @@ class TestLBaaSv2Driver(test_base.TestCase):
820 800
         m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
821 801
 
822 802
         pools = {'name': 'KUKU', 'id': 'a2a62ea7-e3bf-40df-8c09-aa0c29876a6b'}
823
-        lbaas.list_lbaas_pools.return_value = {'pools': [pools]}
803
+        lbaas.pools.return_value = [pools]
824 804
         pool_name = 'NOT_KUKU'
825 805
         project_id = 'TEST_PROJECT'
826 806
 
@@ -859,25 +839,23 @@ class TestLBaaSv2Driver(test_base.TestCase):
859 839
             protocol=pool_protocol,
860 840
             id=pool_id)
861 841
 
862
-        resp = {"pools": [
863
-            {
864
-                "protocol": pool_protocol,
865
-                "loadbalancers": [
866
-                    {
867
-                        "id": pool_lb_id
868
-                    }
869
-                ],
870
-                "listeners": resp_listeners,
871
-                "project_id": pool_project_id,
872
-                "id": pool_id,
873
-                "name": pool_name
874
-            }
875
-        ]}
876
-
877
-        lbaas.list_lbaas_pools.return_value = resp
842
+        resp = [{
843
+            "protocol": pool_protocol,
844
+            "loadbalancers": [
845
+                {
846
+                    "id": pool_lb_id
847
+                }
848
+            ],
849
+            "listeners": resp_listeners,
850
+            "project_id": pool_project_id,
851
+            "id": pool_id,
852
+            "name": pool_name
853
+        }]
854
+
855
+        lbaas.pools.return_value = resp
878 856
 
879 857
         pool = cls.get_pool_by_name(m_driver, pool_name, pool_project_id)
880
-        lbaas.list_lbaas_pools.assert_called_once()
858
+        lbaas.pools.assert_called_once()
881 859
         for attr in expected_result.obj_fields:
882 860
             self.assertEqual(getattr(expected_result, attr),
883 861
                              getattr(pool, attr))
@@ -887,7 +865,7 @@ class TestLBaaSv2Driver(test_base.TestCase):
887 865
         cls = d_lbaasv2.LBaaSv2Driver
888 866
         m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
889 867
         pools = {}
890
-        lbaas.list_lbaas_pools.return_value = {'pools': [pools]}
868
+        lbaas.pools.return_value = [pools]
891 869
         pool_name = 'NOT_KUKU'
892 870
         project_id = 'TEST_PROJECT'
893 871
 
@@ -913,18 +891,18 @@ class TestLBaaSv2Driver(test_base.TestCase):
913 891
             subnet_id=loadbalancer_subnet_id, ip=loadbalancer_vip,
914 892
             security_groups=None, provider=loadbalancer_provider)
915 893
 
916
-        resp = {'loadbalancer': {'id': loadbalancer_id,
917
-                                 'vip_port_id': loadbalancer_vip_port_id,
918
-                                 'name': loadbalancer_name,
919
-                                 'project_id': loadbalancer_project_id,
920
-                                 'vip_subnet_id': loadbalancer_subnet_id,
921
-                                 'vip_address': loadbalancer_vip,
922
-                                 'provider': loadbalancer_provider}}
894
+        resp = {'id': loadbalancer_id,
895
+                'vip_port_id': loadbalancer_vip_port_id,
896
+                'name': loadbalancer_name,
897
+                'project_id': loadbalancer_project_id,
898
+                'vip_subnet_id': loadbalancer_subnet_id,
899
+                'vip_address': loadbalancer_vip,
900
+                'provider': loadbalancer_provider}
923 901
 
924
-        lbaas.show_loadbalancer.return_value = resp
902
+        lbaas.get_load_balancer.return_value = resp
925 903
 
926 904
         ret = cls.get_lb_by_uuid(m_driver, loadbalancer_id)
927
-        lbaas.show_loadbalancer.assert_called_once()
905
+        lbaas.get_load_balancer.assert_called_once()
928 906
         for attr in expected_lb.obj_fields:
929 907
             self.assertEqual(getattr(expected_lb, attr),
930 908
                              getattr(ret, attr))
@@ -936,13 +914,13 @@ class TestLBaaSv2Driver(test_base.TestCase):
936 914
         m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver)
937 915
 
938 916
         resp = {'loadbalancer': {}}
939
-        lbaas.show_loadbalancer.return_value = resp
917
+        lbaas.get_load_balancer.return_value = resp
940 918
 
941 919
         requested_uuid = '00EE9E11-91C2-41CF-8FD4-7970579EFFFF'
942
-        lbaas.show_loadbalancer.return_value = resp
920
+        lbaas.get_load_balancer.side_effect = o_exc.ResourceNotFound
943 921
 
944 922
         ret = cls.get_lb_by_uuid(m_driver, requested_uuid)
945
-        lbaas.show_loadbalancer.assert_called_once()
923
+        lbaas.get_load_balancer.assert_called_once()
946 924
         self.assertIsNone(ret)
947 925
 
948 926
     def test_ensure_l7policy(self):
@@ -987,7 +965,7 @@ class TestLBaaSv2Driver(test_base.TestCase):
987 965
         cls.release_l7_policy(m_driver, loadbalancer, l7_policy)
988 966
 
989 967
         m_driver._release.assert_called_once_with(
990
-            loadbalancer, l7_policy, lbaas.delete_lbaas_l7policy,
968
+            loadbalancer, l7_policy, lbaas.delete_l7_policy,
991 969
             l7_policy.id)
992 970
 
993 971
     def test_create_l7policy(self):
@@ -1002,17 +980,17 @@ class TestLBaaSv2Driver(test_base.TestCase):
1002 980
             redirect_pool_id='D3FA400A-F543-4B91-9CD3-047AF0CE42D1')
1003 981
 
1004 982
         l7policy_id = '3A70CEC0-392D-4BC1-A27C-06E63A0FD54F'
1005
-        req = {'l7policy': {
983
+        req = {
1006 984
             'action': 'REDIRECT_TO_POOL',
1007 985
             'listener_id': l7_policy.listener_id,
1008 986
             'name': l7_policy.name,
1009 987
             'project_id': l7_policy.project_id,
1010
-            'redirect_pool_id': l7_policy.redirect_pool_id}}
1011
-        resp = {'l7policy': {'id': l7policy_id}}
1012
-        lbaas.create_lbaas_l7policy.return_value = resp
988
+            'redirect_pool_id': l7_policy.redirect_pool_id}
989
+        resp = {'id': l7policy_id}
990
+        lbaas.create_l7_policy.return_value = resp
1013 991
 
1014 992
         ret = cls._create_l7_policy(m_driver, l7_policy)
1015
-        lbaas.create_lbaas_l7policy.assert_called_once_with(req)
993
+        lbaas.create_l7_policy.assert_called_once_with(**req)
1016 994
         for attr in l7_policy.obj_fields:
1017 995
             self.assertEqual(getattr(l7_policy, attr),
1018 996
                              getattr(ret, attr))
@@ -1030,11 +1008,11 @@ class TestLBaaSv2Driver(test_base.TestCase):
1030 1008
 
1031 1009
         l7policy_id = '3A70CEC0-392D-4BC1-A27C-06E63A0FD54F'
1032 1010
 
1033
-        resp = {'l7policies': [{'id': l7policy_id}]}
1034
-        lbaas.list_lbaas_l7policies.return_value = resp
1011
+        resp = iter([{'id': l7policy_id}])
1012
+        lbaas.l7_policies.return_value = resp
1035 1013
 
1036 1014
         ret = cls._find_l7_policy(m_driver, l7_policy)
1037
-        lbaas.list_lbaas_l7policies.assert_called_once_with(
1015
+        lbaas.l7_policies.assert_called_once_with(
1038 1016
             name=l7_policy.name,
1039 1017
             project_id=l7_policy.project_id,
1040 1018
             redirect_pool_id=l7_policy.redirect_pool_id,
@@ -1054,11 +1032,11 @@ class TestLBaaSv2Driver(test_base.TestCase):
1054 1032
             listener_id='D4F35594-27EB-4F4C-930C-31DD40F53B77',
1055 1033
             redirect_pool_id='D3FA400A-F543-4B91-9CD3-047AF0CE42D1')
1056 1034
 
1057
-        resp = {'l7policies': []}
1058
-        lbaas.list_lbaas_l7policies.return_value = resp
1035
+        resp = iter([])
1036
+        lbaas.l7_policies.return_value = resp
1059 1037
 
1060 1038
         ret = cls._find_l7_policy(m_driver, l7_policy)
1061
-        lbaas.list_lbaas_l7policies.assert_called_once_with(
1039
+        lbaas.l7_policies.assert_called_once_with(
1062 1040
             name=l7_policy.name,
1063 1041
             project_id=l7_policy.project_id,
1064 1042
             redirect_pool_id=l7_policy.redirect_pool_id,
@@ -1104,7 +1082,7 @@ class TestLBaaSv2Driver(test_base.TestCase):
1104 1082
         cls.release_l7_rule(m_driver, loadbalancer, l7_rule)
1105 1083
 
1106 1084
         m_driver._release.assert_called_once_with(
1107
-            loadbalancer, l7_rule, lbaas.delete_lbaas_l7rule,
1085
+            loadbalancer, l7_rule, lbaas.delete_l7_rule,
1108 1086
             l7_rule.id, l7_rule.l7policy_id)
1109 1087
 
1110 1088
     def test_create_l7_rule(self):
@@ -1120,17 +1098,16 @@ class TestLBaaSv2Driver(test_base.TestCase):
1120 1098
 
1121 1099
         l7_rule_id = '3A70CEC0-392D-4BC1-A27C-06E63A0FD54F'
1122 1100
 
1123
-        req = {'rule': {
1124
-            'compare_type': l7_rule.compare_type,
1125
-            'type': l7_rule.type,
1126
-            'value': l7_rule.value}}
1101
+        req = {'compare_type': l7_rule.compare_type,
1102
+               'type': l7_rule.type,
1103
+               'value': l7_rule.value}
1127 1104
 
1128
-        resp = {'rule': {'id': l7_rule_id}}
1129
-        lbaas.create_lbaas_l7rule.return_value = resp
1105
+        resp = {'id': l7_rule_id}
1106
+        lbaas.create_l7_rule.return_value = resp
1130 1107
 
1131 1108
         ret = cls._create_l7_rule(m_driver, l7_rule)
1132
-        lbaas.create_lbaas_l7rule.assert_called_once_with(
1133
-            l7_rule.l7policy_id, req)
1109
+        lbaas.create_l7_rule.assert_called_once_with(l7_rule.l7policy_id,
1110
+                                                     **req)
1134 1111
         for attr in l7_rule.obj_fields:
1135 1112
             self.assertEqual(getattr(l7_rule, attr),
1136 1113
                              getattr(ret, attr))
@@ -1147,11 +1124,11 @@ class TestLBaaSv2Driver(test_base.TestCase):
1147 1124
             value='www.test.com')
1148 1125
 
1149 1126
         l7_rule_id = '3A70CEC0-392D-4BC1-A27C-06E63A0FD54F'
1150
-        resp = {'rules': [{'id': l7_rule_id}]}
1151
-        lbaas.list_lbaas_l7rules.return_value = resp
1127
+        resp = iter([{'id': l7_rule_id}])
1128
+        lbaas.l7_rules.return_value = resp
1152 1129
 
1153 1130
         ret = cls._find_l7_rule(m_driver, l7_rule)
1154
-        lbaas.list_lbaas_l7rules.assert_called_once_with(
1131
+        lbaas.l7_rules.assert_called_once_with(
1155 1132
             l7_rule.l7policy_id,
1156 1133
             type=l7_rule.type,
1157 1134
             value=l7_rule.value,
@@ -1172,11 +1149,11 @@ class TestLBaaSv2Driver(test_base.TestCase):
1172 1149
             type='HOST_NAME',
1173 1150
             value='www.test.com')
1174 1151
 
1175
-        resp = {'rules': []}
1176
-        lbaas.list_lbaas_l7rules.return_value = resp
1152
+        resp = iter([])
1153
+        lbaas.l7_rules.return_value = resp
1177 1154
 
1178 1155
         ret = cls._find_l7_rule(m_driver, l7_rule)
1179
-        lbaas.list_lbaas_l7rules.assert_called_once_with(
1156
+        lbaas.l7_rules.assert_called_once_with(
1180 1157
             l7_rule.l7policy_id,
1181 1158
             type=l7_rule.type,
1182 1159
             value=l7_rule.value,

+ 0
- 20
kuryr_kubernetes/tests/unit/controller/handlers/test_lbaas.py View File

@@ -608,25 +608,6 @@ class TestLoadBalancerHandler(test_base.TestCase):
608 608
         m_handler.on_deleted.assert_called_once_with(
609 609
             endpoints, lbaas_state)
610 610
 
611
-    @mock.patch('kuryr_kubernetes.objects.lbaas'
612
-                '.LBaaSServiceSpec')
613
-    def test_on_deleted(self, m_svc_spec_ctor):
614
-        endpoints = mock.sentinel.endpoints
615
-        empty_spec = mock.sentinel.empty_spec
616
-        lbaas_state = mock.sentinel.lbaas_state
617
-        m_svc_spec_ctor.return_value = empty_spec
618
-
619
-        m_handler = mock.Mock(spec=h_lbaas.LoadBalancerHandler)
620
-        m_handler._get_lbaas_state.return_value = lbaas_state
621
-        m_handler._drv_lbaas = mock.Mock()
622
-        m_handler._drv_lbaas.cascading_capable = False
623
-
624
-        h_lbaas.LoadBalancerHandler.on_deleted(m_handler, endpoints)
625
-
626
-        m_handler._get_lbaas_state.assert_called_once_with(endpoints)
627
-        m_handler._sync_lbaas_members.assert_called_once_with(
628
-            endpoints, lbaas_state, empty_spec)
629
-
630 611
     @mock.patch('kuryr_kubernetes.objects.lbaas'
631 612
                 '.LBaaSServiceSpec')
632 613
     def test_on_cascade_deleted_lb_service(self, m_svc_spec_ctor):
@@ -641,7 +622,6 @@ class TestLoadBalancerHandler(test_base.TestCase):
641 622
         m_handler._get_lbaas_state.return_value = lbaas_state
642 623
         m_handler._drv_lbaas = mock.Mock()
643 624
         m_handler._drv_service_pub_ip = mock.Mock()
644
-        m_handler._drv_lbaas.cascading_capable = True
645 625
 
646 626
         h_lbaas.LoadBalancerHandler.on_deleted(m_handler, endpoints)
647 627
 

+ 8
- 3
kuryr_kubernetes/tests/unit/controller/handlers/test_vif.py View File

@@ -89,21 +89,25 @@ class TestVIFHandler(test_base.TestCase):
89 89
     @mock.patch.object(drivers.PodSecurityGroupsDriver, 'get_instance')
90 90
     @mock.patch.object(drivers.PodSubnetsDriver, 'get_instance')
91 91
     @mock.patch.object(drivers.PodProjectDriver, 'get_instance')
92
-    def test_init(self, m_get_project_driver, m_get_subnets_driver,
93
-                  m_get_sg_driver, m_get_vif_driver, m_get_vif_pool_driver,
94
-                  m_set_vifs_driver, m_get_multi_vif_drivers):
92
+    @mock.patch.object(drivers.LBaaSDriver, 'get_instance')
93
+    def test_init(self, m_get_lbaas_driver, m_get_project_driver,
94
+                  m_get_subnets_driver, m_get_sg_driver, m_get_vif_driver,
95
+                  m_get_vif_pool_driver, m_set_vifs_driver,
96
+                  m_get_multi_vif_drivers):
95 97
         project_driver = mock.sentinel.project_driver
96 98
         subnets_driver = mock.sentinel.subnets_driver
97 99
         sg_driver = mock.sentinel.sg_driver
98 100
         vif_driver = mock.sentinel.vif_driver
99 101
         vif_pool_driver = mock.Mock(spec=drivers.VIFPoolDriver)
100 102
         multi_vif_drivers = [mock.MagicMock(spec=drivers.MultiVIFDriver)]
103
+        lbaas_driver = mock.sentinel.lbaas_driver
101 104
         m_get_project_driver.return_value = project_driver
102 105
         m_get_subnets_driver.return_value = subnets_driver
103 106
         m_get_sg_driver.return_value = sg_driver
104 107
         m_get_vif_driver.return_value = vif_driver
105 108
         m_get_vif_pool_driver.return_value = vif_pool_driver
106 109
         m_get_multi_vif_drivers.return_value = multi_vif_drivers
110
+        m_get_lbaas_driver.return_value = lbaas_driver
107 111
 
108 112
         handler = h_vif.VIFHandler()
109 113
 
@@ -112,6 +116,7 @@ class TestVIFHandler(test_base.TestCase):
112 116
         self.assertEqual(sg_driver, handler._drv_sg)
113 117
         self.assertEqual(vif_pool_driver, handler._drv_vif_pool)
114 118
         self.assertEqual(multi_vif_drivers, handler._drv_multi_vif)
119
+        self.assertEqual(lbaas_driver, handler._drv_lbaas)
115 120
 
116 121
     def test_is_pending_node(self):
117 122
         self.assertTrue(h_vif.VIFHandler._is_pending_node(self._pod))

+ 8
- 40
kuryr_kubernetes/tests/unit/test_clients.py View File

@@ -21,60 +21,28 @@ from kuryr_kubernetes.tests import base as test_base
21 21
 
22 22
 class TestK8sClient(test_base.TestCase):
23 23
 
24
+    @mock.patch('openstack.connection.Connection')
24 25
     @mock.patch('kuryr_kubernetes.config.CONF')
25 26
     @mock.patch('kuryr_kubernetes.k8s_client.K8sClient')
26 27
     @mock.patch('kuryr.lib.utils.get_neutron_client')
27
-    def test_setup_clients_lbaasv2(self, m_neutron, m_k8s, m_cfg):
28
+    def test_setup_clients(self, m_neutron, m_k8s, m_cfg, m_openstack):
28 29
         k8s_api_root = 'http://127.0.0.1:1234'
29 30
 
30 31
         neutron_mock = mock.Mock()
32
+        openstacksdk_mock = mock.Mock()
33
+        openstacksdk_mock.load_balancer = mock.Mock()
31 34
         k8s_dummy = object()
32 35
 
33
-        neutron_mock.list_extensions.return_value = {
34
-            'extensions': [
35
-                {'alias': 'lbaasv2',
36
-                 'description': 'Provides Load Balancing',
37
-                 'links': [],
38
-                 'name': 'Load Balancing v2',
39
-                 'updated': '2017-11-28T09:00:00-00:00'}]}
40
-
41
-        m_cfg.kubernetes.api_root = k8s_api_root
42
-        m_neutron.return_value = neutron_mock
43
-        m_k8s.return_value = k8s_dummy
44
-
45
-        clients.setup_clients()
46
-
47
-        m_k8s.assert_called_with(k8s_api_root)
48
-        self.assertIs(k8s_dummy, clients.get_kubernetes_client())
49
-        self.assertIs(neutron_mock, clients.get_neutron_client())
50
-        self.assertIs(neutron_mock, clients.get_loadbalancer_client())
51
-
52
-    @mock.patch('neutronclient.client.construct_http_client')
53
-    @mock.patch('kuryr.lib.utils.get_auth_plugin')
54
-    @mock.patch('kuryr_kubernetes.config.CONF')
55
-    @mock.patch('kuryr_kubernetes.k8s_client.K8sClient')
56
-    @mock.patch('kuryr.lib.utils.get_neutron_client')
57
-    def test_setup_clients_octavia(self, m_neutron, m_k8s, m_cfg,
58
-                                   m_auth_plugin, m_construct_http_client):
59
-        k8s_api_root = 'http://127.0.0.1:1234'
60
-
61
-        neutron_mock = mock.Mock()
62
-        k8s_dummy = object()
63
-
64
-        neutron_mock.list_extensions.return_value = {
65
-            'extensions': []}
66
-
67
-        octavia_httpclient = mock.sentinel.octavia_httpclient
68
-        m_construct_http_client.return_value = octavia_httpclient
69
-        m_auth_plugin.return_value = mock.sentinel.auth_plugin
70 36
         m_cfg.kubernetes.api_root = k8s_api_root
71 37
         m_neutron.return_value = neutron_mock
72 38
         m_k8s.return_value = k8s_dummy
39
+        m_openstack.return_value = openstacksdk_mock
73 40
 
74 41
         clients.setup_clients()
75 42
 
76 43
         m_k8s.assert_called_with(k8s_api_root)
77 44
         self.assertIs(k8s_dummy, clients.get_kubernetes_client())
78 45
         self.assertIs(neutron_mock, clients.get_neutron_client())
79
-        self.assertIs(octavia_httpclient,
80
-                      clients.get_loadbalancer_client().httpclient)
46
+        self.assertIs(openstacksdk_mock, clients.get_openstacksdk())
47
+        self.assertIs(openstacksdk_mock.load_balancer,
48
+                      clients.get_loadbalancer_client())

+ 1
- 1
lower-constraints.txt View File

@@ -55,7 +55,7 @@ netaddr==0.7.19
55 55
 netifaces==0.10.6
56 56
 neutron-lib==1.13.0
57 57
 openstackdocstheme==1.18.1
58
-openstacksdk==0.12.0
58
+openstacksdk==0.13.0
59 59
 os-client-config==1.29.0
60 60
 os-service-types==1.2.0
61 61
 os-testr==1.0.0

+ 1
- 0
requirements.txt View File

@@ -8,6 +8,7 @@ kuryr-lib>=0.5.0 # Apache-2.0
8 8
 pbr!=2.1.0,>=2.0.0 # Apache-2.0
9 9
 requests>=2.14.2 # Apache-2.0
10 10
 eventlet!=0.18.3,!=0.20.1,!=0.21.0,>=0.18.2 # MIT
11
+openstacksdk>=0.13.0  # Apache-2.0
11 12
 oslo.cache>=1.26.0 # Apache-2.0
12 13
 oslo.config>=5.2.0 # Apache-2.0
13 14
 oslo.log>=3.36.0 # Apache-2.0

Loading…
Cancel
Save