"Fossies" - the Fresh Open Source Software Archive

Member "magnum-8.1.0/magnum/tests/unit/conductor/handlers/test_k8s_cluster_conductor.py" (1 Oct 2019, 52008 Bytes) of package /linux/misc/openstack/magnum-8.1.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "test_k8s_cluster_conductor.py": 8.0.0_vs_8.1.0.

    1 # Copyright 2015 Hewlett-Packard Development Company, L.P.
    2 #
    3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
    4 # not use this file except in compliance with the License. You may obtain
    5 # a copy of the License at
    6 #
    7 #      http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 # Unless required by applicable law or agreed to in writing, software
   10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   12 # License for the specific language governing permissions and limitations
   13 # under the License.
   14 
   15 import mock
   16 from mock import patch
   17 
   18 import magnum.conf
   19 from magnum.drivers.k8s_coreos_v1 import driver as k8s_coreos_dr
   20 from magnum.drivers.k8s_fedora_atomic_v1 import driver as k8s_dr
   21 from magnum import objects
   22 from magnum.tests import base
   23 
   24 CONF = magnum.conf.CONF
   25 
   26 
   27 class TestClusterConductorWithK8s(base.TestCase):
   28     def setUp(self):
   29         super(TestClusterConductorWithK8s, self).setUp()
   30         self.cluster_template_dict = {
   31             'image_id': 'image_id',
   32             'flavor_id': 'flavor_id',
   33             'master_flavor_id': 'master_flavor_id',
   34             'keypair_id': 'keypair_id',
   35             'dns_nameserver': 'dns_nameserver',
   36             'external_network_id': 'e2a6c8b0-a3c2-42a3-b3f4-01400a30896e',
   37             'fixed_network': 'fixed_network',
   38             'fixed_subnet': 'fixed_subnet',
   39             'network_driver': 'network_driver',
   40             'volume_driver': 'volume_driver',
   41             'docker_volume_size': 20,
   42             'master_flavor_id': 'flavor_id',
   43             'docker_storage_driver': 'devicemapper',
   44             'cluster_distro': 'fedora-atomic',
   45             'coe': 'kubernetes',
   46             'token': None,
   47             'http_proxy': 'http_proxy',
   48             'https_proxy': 'https_proxy',
   49             'no_proxy': 'no_proxy',
   50             'labels': {'flannel_network_cidr': '10.101.0.0/16',
   51                        'flannel_network_subnetlen': '26',
   52                        'flannel_backend': 'vxlan',
   53                        'system_pods_initial_delay': '15',
   54                        'system_pods_timeout': '1',
   55                        'admission_control_list': 'fake_list',
   56                        'prometheus_monitoring': 'False',
   57                        'grafana_admin_passwd': 'fake_pwd',
   58                        'kube_dashboard_enabled': 'True',
   59                        'influx_grafana_dashboard_enabled': 'True',
   60                        'docker_volume_type': 'lvmdriver-1',
   61                        'etcd_volume_size': 0,
   62                        'availability_zone': 'az_1',
   63                        'service_cluster_ip_range': '10.254.0.0/16'},
   64             'tls_disabled': False,
   65             'server_type': 'vm',
   66             'registry_enabled': False,
   67             'insecure_registry': '10.0.0.1:5000',
   68             'master_lb_enabled': False,
   69             'floating_ip_enabled': False,
   70         }
   71         self.cluster_dict = {
   72             'uuid': '5d12f6fd-a196-4bf0-ae4c-1f639a523a52',
   73             'cluster_template_id': 'xx-xx-xx-xx',
   74             'keypair': 'keypair_id',
   75             'name': 'cluster1',
   76             'stack_id': 'xx-xx-xx-xx',
   77             'api_address': '172.17.2.3',
   78             'node_addresses': ['172.17.2.4'],
   79             'node_count': 1,
   80             'master_count': 1,
   81             'discovery_url': 'https://discovery.etcd.io/test',
   82             'docker_volume_size': 20,
   83             'flavor_id': 'flavor_id',
   84             'master_addresses': ['172.17.2.18'],
   85             'ca_cert_ref': 'http://barbican/v1/containers/xx-xx-xx-xx',
   86             'magnum_cert_ref': 'http://barbican/v1/containers/xx-xx-xx-xx',
   87             'trustee_username': 'fake_trustee',
   88             'trustee_password': 'fake_trustee_password',
   89             'trustee_user_id': '7b489f04-b458-4541-8179-6a48a553e656',
   90             'trust_id': 'bd11efc5-d4e2-4dac-bbce-25e348ddf7de',
   91             'coe_version': 'fake-version',
   92             'labels': {'flannel_network_cidr': '10.101.0.0/16',
   93                        'flannel_network_subnetlen': '26',
   94                        'flannel_backend': 'vxlan',
   95                        'system_pods_initial_delay': '15',
   96                        'system_pods_timeout': '1',
   97                        'admission_control_list': 'fake_list',
   98                        'prometheus_monitoring': 'False',
   99                        'grafana_admin_passwd': 'fake_pwd',
  100                        'kube_dashboard_enabled': 'True',
  101                        'docker_volume_type': 'lvmdriver-1',
  102                        'availability_zone': 'az_1',
  103                        'cert_manager_api': 'False',
  104                        'ingress_controller': 'i-controller',
  105                        'ingress_controller_role': 'i-controller-role',
  106                        'kubelet_options': '--kubelet',
  107                        'kubeapi_options': '--kubeapi',
  108                        'kubecontroller_options': '--kubecontroller',
  109                        'kubescheduler_options': '--kubescheduler',
  110                        'kubeproxy_options': '--kubeproxy',
  111                        'influx_grafana_dashboard_enabled': 'True',
  112                        'max_node_count': '2',
  113                        'service_cluster_ip_range': '10.254.0.0/16'},
  114             'master_flavor_id': 'master_flavor_id',
  115             'flavor_id': 'flavor_id',
  116             'project_id': 'project_id',
  117         }
  118         self.context.user_name = 'fake_user'
  119         self.context.project_id = 'fake_tenant'
  120         osc_patcher = mock.patch('magnum.common.clients.OpenStackClients')
  121         self.mock_osc_class = osc_patcher.start()
  122         self.addCleanup(osc_patcher.stop)
  123         self.mock_osc = mock.MagicMock()
  124         self.mock_osc.url_for.return_value = 'http://192.168.10.10:5000/v3'
  125         self.mock_osc.magnum_url.return_value = 'http://127.0.0.1:9511/v1'
  126         self.mock_osc.cinder_region_name.return_value = 'RegionOne'
  127         self.mock_keystone = mock.MagicMock()
  128         self.mock_keystone.trustee_domain_id = 'trustee_domain_id'
  129         self.mock_osc.keystone.return_value = self.mock_keystone
  130         self.mock_osc_class.return_value = self.mock_osc
  131 
  132         octavia_patcher = mock.patch(
  133             'magnum.common.keystone.is_octavia_enabled'
  134         )
  135         self.mock_enable_octavia = octavia_patcher.start()
  136         self.mock_enable_octavia.return_value = False
  137         self.addCleanup(octavia_patcher.stop)
  138 
  139     @patch('requests.get')
  140     @patch('magnum.objects.ClusterTemplate.get_by_uuid')
  141     @patch('magnum.drivers.common.driver.Driver.get_driver')
  142     @patch('magnum.conductor.handlers.common.cert_manager'
  143            '.sign_node_certificate')
  144     @patch('magnum.common.x509.operations.generate_csr_and_key')
  145     def test_extract_template_definition(
  146             self,
  147             mock_generate_csr_and_key,
  148             mock_sign_node_certificate,
  149             mock_driver,
  150             mock_objects_cluster_template_get_by_uuid,
  151             mock_get):
  152         self._test_extract_template_definition(
  153             mock_generate_csr_and_key, mock_sign_node_certificate,
  154             mock_driver, mock_objects_cluster_template_get_by_uuid, mock_get)
  155 
  156     def _test_extract_template_definition(
  157             self,
  158             mock_generate_csr_and_key,
  159             mock_sign_node_certificate,
  160             mock_driver,
  161             mock_objects_cluster_template_get_by_uuid,
  162             mock_get,
  163             missing_attr=None):
  164         if missing_attr in self.cluster_template_dict:
  165             self.cluster_template_dict[missing_attr] = None
  166         elif missing_attr in self.cluster_dict:
  167             self.cluster_dict[missing_attr] = None
  168         cluster_template = objects.ClusterTemplate(
  169             self.context, **self.cluster_template_dict)
  170         mock_generate_csr_and_key.return_value = {'csr': 'csr',
  171                                                   'private_key': 'private_key',
  172                                                   'public_key': 'public_key'}
  173         mock_sign_node_certificate.return_value = 'signed_cert'
  174         mock_objects_cluster_template_get_by_uuid.return_value = \
  175             cluster_template
  176         expected_result = str('{"action":"get","node":{"key":"test","value":'
  177                               '"1","modifiedIndex":10,"createdIndex":10}}')
  178         mock_resp = mock.MagicMock()
  179         mock_resp.text = expected_result
  180         mock_resp.status_code = 200
  181         mock_get.return_value = mock_resp
  182         cluster = objects.Cluster(self.context, **self.cluster_dict)
  183         mock_driver.return_value = k8s_dr.Driver()
  184 
  185         (template_path,
  186          definition,
  187          env_files) = mock_driver()._extract_template_definition(self.context,
  188                                                                  cluster)
  189 
  190         mapping = {
  191             'dns_nameserver': 'dns_nameserver',
  192             'image_id': 'server_image',
  193             'flavor_id': 'minion_flavor',
  194             'docker_volume_size': 'docker_volume_size',
  195             'docker_storage_driver': 'docker_storage_driver',
  196             'network_driver': 'network_driver',
  197             'volume_driver': 'volume_driver',
  198             'master_flavor_id': 'master_flavor',
  199             'apiserver_port': '',
  200             'node_count': 'number_of_minions',
  201             'master_count': 'number_of_masters',
  202             'discovery_url': 'discovery_url',
  203             'labels': {'flannel_network_cidr': '10.101.0.0/16',
  204                        'flannel_network_subnetlen': '26',
  205                        'flannel_backend': 'vxlan',
  206                        'system_pods_initial_delay': '15',
  207                        'system_pods_timeout': '1',
  208                        'admission_control_list': 'fake_list',
  209                        'prometheus_monitoring': 'False',
  210                        'grafana_admin_passwd': 'fake_pwd',
  211                        'kube_dashboard_enabled': 'True',
  212                        'influx_grafana_dashboard_enabled': 'True',
  213                        'docker_volume_type': 'lvmdriver-1',
  214                        'etcd_volume_size': None,
  215                        'availability_zone': 'az_1',
  216                        'cert_manager_api': 'False',
  217                        'ingress_controller': 'i-controller',
  218                        'ingress_controller_role': 'i-controller-role',
  219                        'kubelet_options': '--kubelet',
  220                        'kubeapi_options': '--kubeapi',
  221                        'kubecontroller_options': '--kubecontroller',
  222                        'kubescheduler_options': '--kubescheduler',
  223                        'kubeproxy_options': '--kubeproxy',
  224                        'service_cluster_ip_range': '10.254.0.0/16',
  225                        },
  226             'http_proxy': 'http_proxy',
  227             'https_proxy': 'https_proxy',
  228             'no_proxy': 'no_proxy',
  229             'cluster_uuid': self.cluster_dict['uuid'],
  230             'magnum_url': self.mock_osc.magnum_url.return_value,
  231             'tls_disabled': False,
  232             'insecure_registry': '10.0.0.1:5000',
  233         }
  234         expected = {
  235             'cloud_provider_enabled': 'false',
  236             'ssh_key_name': 'keypair_id',
  237             'external_network': 'e2a6c8b0-a3c2-42a3-b3f4-01400a30896e',
  238             'fixed_network': 'fixed_network',
  239             'fixed_subnet': 'fixed_subnet',
  240             'network_driver': 'network_driver',
  241             'volume_driver': 'volume_driver',
  242             'dns_nameserver': 'dns_nameserver',
  243             'server_image': 'image_id',
  244             'minion_flavor': 'flavor_id',
  245             'master_flavor': 'master_flavor_id',
  246             'number_of_minions': 1,
  247             'number_of_masters': 1,
  248             'docker_volume_size': 20,
  249             'docker_volume_type': 'lvmdriver-1',
  250             'docker_storage_driver': 'devicemapper',
  251             'discovery_url': 'https://discovery.etcd.io/test',
  252             'etcd_volume_size': None,
  253             'flannel_network_cidr': '10.101.0.0/16',
  254             'flannel_network_subnetlen': '26',
  255             'flannel_backend': 'vxlan',
  256             'system_pods_initial_delay': '15',
  257             'system_pods_timeout': '1',
  258             'admission_control_list': 'fake_list',
  259             'prometheus_monitoring': 'False',
  260             'grafana_admin_passwd': 'fake_pwd',
  261             'kube_dashboard_enabled': 'True',
  262             'influx_grafana_dashboard_enabled': 'True',
  263             'http_proxy': 'http_proxy',
  264             'https_proxy': 'https_proxy',
  265             'no_proxy': 'no_proxy',
  266             'username': 'fake_user',
  267             'cluster_uuid': self.cluster_dict['uuid'],
  268             'magnum_url': self.mock_osc.magnum_url.return_value,
  269             'region_name': self.mock_osc.cinder_region_name.return_value,
  270             'tls_disabled': False,
  271             'registry_enabled': False,
  272             'trustee_domain_id': self.mock_keystone.trustee_domain_id,
  273             'trustee_username': 'fake_trustee',
  274             'trustee_password': 'fake_trustee_password',
  275             'trustee_user_id': '7b489f04-b458-4541-8179-6a48a553e656',
  276             'trust_id': '',
  277             'auth_url': 'http://192.168.10.10:5000/v3',
  278             'insecure_registry_url': '10.0.0.1:5000',
  279             'kube_version': 'fake-version',
  280             'verify_ca': True,
  281             'openstack_ca': '',
  282             "nodes_affinity_policy": "soft-anti-affinity",
  283             'availability_zone': 'az_1',
  284             'cert_manager_api': 'False',
  285             'ingress_controller': 'i-controller',
  286             'ingress_controller_role': 'i-controller-role',
  287             'octavia_ingress_controller_tag': None,
  288             'kubelet_options': '--kubelet',
  289             'kubeapi_options': '--kubeapi',
  290             'kubecontroller_options': '--kubecontroller',
  291             'kubescheduler_options': '--kubescheduler',
  292             'kubeproxy_options': '--kubeproxy',
  293             'octavia_enabled': False,
  294             'kube_service_account_key': 'public_key',
  295             'kube_service_account_private_key': 'private_key',
  296             'portal_network_cidr': '10.254.0.0/16',
  297             'project_id': 'project_id',
  298             'max_node_count': '2',
  299         }
  300         if missing_attr is not None:
  301             expected.pop(mapping[missing_attr], None)
  302 
  303         self.assertEqual(expected, definition)
  304         self.assertEqual(
  305             ['../../common/templates/environments/no_private_network.yaml',
  306              '../../common/templates/environments/no_etcd_volume.yaml',
  307              '../../common/templates/environments/with_volume.yaml',
  308              '../../common/templates/environments/no_master_lb.yaml',
  309              '../../common/templates/environments/disable_floating_ip.yaml',
  310              '../../common/templates/environments/disable_lb_floating_ip.yaml',
  311              ],
  312             env_files)
  313 
  314     @patch('requests.get')
  315     @patch('magnum.objects.ClusterTemplate.get_by_uuid')
  316     @patch('magnum.drivers.common.driver.Driver.get_driver')
  317     @patch('magnum.conductor.handlers.common.cert_manager'
  318            '.sign_node_certificate')
  319     @patch('magnum.common.x509.operations.generate_csr_and_key')
  320     def test_extract_template_definition_with_registry(
  321             self,
  322             mock_generate_csr_and_key,
  323             mock_sign_node_certificate,
  324             mock_driver,
  325             mock_objects_cluster_template_get_by_uuid,
  326             mock_get):
  327         self.cluster_template_dict['registry_enabled'] = True
  328         cluster_template = objects.ClusterTemplate(
  329             self.context, **self.cluster_template_dict)
  330         mock_generate_csr_and_key.return_value = {'csr': 'csr',
  331                                                   'private_key': 'private_key',
  332                                                   'public_key': 'public_key'}
  333         mock_sign_node_certificate.return_value = 'signed_cert'
  334         mock_objects_cluster_template_get_by_uuid.return_value = \
  335             cluster_template
  336         expected_result = str('{"action":"get","node":{"key":"test","value":'
  337                               '"1","modifiedIndex":10,"createdIndex":10}}')
  338         mock_resp = mock.MagicMock()
  339         mock_resp.text = expected_result
  340         mock_get.return_value = mock_resp
  341         cluster = objects.Cluster(self.context, **self.cluster_dict)
  342         mock_driver.return_value = k8s_dr.Driver()
  343 
  344         CONF.set_override('swift_region',
  345                           'RegionOne',
  346                           group='docker_registry')
  347 
  348         CONF.set_override('cluster_user_trust',
  349                           True,
  350                           group='trust')
  351 
  352         (template_path,
  353          definition,
  354          env_files) = mock_driver()._extract_template_definition(self.context,
  355                                                                  cluster)
  356 
  357         expected = {
  358             'auth_url': 'http://192.168.10.10:5000/v3',
  359             'cloud_provider_enabled': 'true',
  360             'cluster_uuid': '5d12f6fd-a196-4bf0-ae4c-1f639a523a52',
  361             'discovery_url': 'https://discovery.etcd.io/test',
  362             'dns_nameserver': 'dns_nameserver',
  363             'docker_storage_driver': 'devicemapper',
  364             'docker_volume_size': 20,
  365             'docker_volume_type': 'lvmdriver-1',
  366             'etcd_volume_size': None,
  367             'external_network': 'e2a6c8b0-a3c2-42a3-b3f4-01400a30896e',
  368             'fixed_network': 'fixed_network',
  369             'fixed_subnet': 'fixed_subnet',
  370             'flannel_backend': 'vxlan',
  371             'flannel_network_cidr': '10.101.0.0/16',
  372             'flannel_network_subnetlen': '26',
  373             'system_pods_initial_delay': '15',
  374             'system_pods_timeout': '1',
  375             'admission_control_list': 'fake_list',
  376             'prometheus_monitoring': 'False',
  377             'grafana_admin_passwd': 'fake_pwd',
  378             'kube_dashboard_enabled': 'True',
  379             'influx_grafana_dashboard_enabled': 'True',
  380             'http_proxy': 'http_proxy',
  381             'https_proxy': 'https_proxy',
  382             'magnum_url': 'http://127.0.0.1:9511/v1',
  383             'master_flavor': 'master_flavor_id',
  384             'minion_flavor': 'flavor_id',
  385             'network_driver': 'network_driver',
  386             'no_proxy': 'no_proxy',
  387             'number_of_masters': 1,
  388             'number_of_minions': 1,
  389             'region_name': 'RegionOne',
  390             'registry_container': 'docker_registry',
  391             'registry_enabled': True,
  392             'server_image': 'image_id',
  393             'ssh_key_name': 'keypair_id',
  394             'swift_region': 'RegionOne',
  395             'tls_disabled': False,
  396             'trust_id': 'bd11efc5-d4e2-4dac-bbce-25e348ddf7de',
  397             'trustee_domain_id': self.mock_keystone.trustee_domain_id,
  398             'trustee_password': 'fake_trustee_password',
  399             'trustee_user_id': '7b489f04-b458-4541-8179-6a48a553e656',
  400             'trustee_username': 'fake_trustee',
  401             'username': 'fake_user',
  402             'volume_driver': 'volume_driver',
  403             'insecure_registry_url': '10.0.0.1:5000',
  404             'kube_version': 'fake-version',
  405             'verify_ca': True,
  406             'openstack_ca': '',
  407             "nodes_affinity_policy": "soft-anti-affinity",
  408             'availability_zone': 'az_1',
  409             'cert_manager_api': 'False',
  410             'ingress_controller': 'i-controller',
  411             'ingress_controller_role': 'i-controller-role',
  412             'octavia_ingress_controller_tag': None,
  413             'kubelet_options': '--kubelet',
  414             'kubeapi_options': '--kubeapi',
  415             'kubecontroller_options': '--kubecontroller',
  416             'kubescheduler_options': '--kubescheduler',
  417             'kubeproxy_options': '--kubeproxy',
  418             'octavia_enabled': False,
  419             'kube_service_account_key': 'public_key',
  420             'kube_service_account_private_key': 'private_key',
  421             'portal_network_cidr': '10.254.0.0/16',
  422             'project_id': 'project_id',
  423             'max_node_count': '2',
  424         }
  425 
  426         self.assertEqual(expected, definition)
  427         self.assertEqual(
  428             ['../../common/templates/environments/no_private_network.yaml',
  429              '../../common/templates/environments/no_etcd_volume.yaml',
  430              '../../common/templates/environments/with_volume.yaml',
  431              '../../common/templates/environments/no_master_lb.yaml',
  432              '../../common/templates/environments/disable_floating_ip.yaml',
  433              '../../common/templates/environments/disable_lb_floating_ip.yaml'
  434              ],
  435             env_files)
  436 
  437     @patch('requests.get')
  438     @patch('magnum.objects.ClusterTemplate.get_by_uuid')
  439     @patch('magnum.drivers.common.driver.Driver.get_driver')
  440     @patch('magnum.conductor.handlers.common.cert_manager'
  441            '.sign_node_certificate')
  442     @patch('magnum.common.x509.operations.generate_csr_and_key')
  443     def test_extract_template_definition_only_required(
  444             self,
  445             mock_generate_csr_and_key,
  446             mock_sign_node_certificate,
  447             mock_driver,
  448             mock_objects_cluster_template_get_by_uuid,
  449             mock_get):
  450 
  451         not_required = ['image_id', 'flavor_id', 'dns_nameserver',
  452                         'docker_volume_size', 'fixed_network', 'http_proxy',
  453                         'https_proxy', 'no_proxy', 'network_driver',
  454                         'master_flavor_id', 'docker_storage_driver',
  455                         'volume_driver', 'fixed_subnet']
  456         for key in not_required:
  457             self.cluster_template_dict[key] = None
  458         self.cluster_dict['discovery_url'] = 'https://discovery.etcd.io/test'
  459 
  460         cluster_template = objects.ClusterTemplate(
  461             self.context, **self.cluster_template_dict)
  462         mock_generate_csr_and_key.return_value = {'csr': 'csr',
  463                                                   'private_key': 'private_key',
  464                                                   'public_key': 'public_key'}
  465         mock_sign_node_certificate.return_value = 'signed_cert'
  466         mock_objects_cluster_template_get_by_uuid.return_value = \
  467             cluster_template
  468         expected_result = str('{"action":"get","node":{"key":"test","value":'
  469                               '"1","modifiedIndex":10,"createdIndex":10}}')
  470         mock_resp = mock.MagicMock()
  471         mock_resp.text = expected_result
  472         mock_get.return_value = mock_resp
  473         mock_driver.return_value = k8s_dr.Driver()
  474         cluster = objects.Cluster(self.context, **self.cluster_dict)
  475 
  476         (template_path,
  477          definition,
  478          env_files) = mock_driver()._extract_template_definition(self.context,
  479                                                                  cluster)
  480 
  481         expected = {
  482             'auth_url': 'http://192.168.10.10:5000/v3',
  483             'cloud_provider_enabled': 'false',
  484             'cluster_uuid': '5d12f6fd-a196-4bf0-ae4c-1f639a523a52',
  485             'discovery_url': 'https://discovery.etcd.io/test',
  486             'docker_volume_size': 20,
  487             'master_flavor': 'master_flavor_id',
  488             'minion_flavor': 'flavor_id',
  489             'external_network': 'e2a6c8b0-a3c2-42a3-b3f4-01400a30896e',
  490             'flannel_backend': 'vxlan',
  491             'flannel_network_cidr': '10.101.0.0/16',
  492             'flannel_network_subnetlen': '26',
  493             'system_pods_initial_delay': '15',
  494             'system_pods_timeout': '1',
  495             'admission_control_list': 'fake_list',
  496             'prometheus_monitoring': 'False',
  497             'grafana_admin_passwd': 'fake_pwd',
  498             'kube_dashboard_enabled': 'True',
  499             'influx_grafana_dashboard_enabled': 'True',
  500             'docker_volume_type': 'lvmdriver-1',
  501             'etcd_volume_size': None,
  502             'insecure_registry_url': '10.0.0.1:5000',
  503             'kube_version': 'fake-version',
  504             'magnum_url': 'http://127.0.0.1:9511/v1',
  505             'number_of_masters': 1,
  506             'number_of_minions': 1,
  507             'region_name': 'RegionOne',
  508             'registry_enabled': False,
  509             'ssh_key_name': 'keypair_id',
  510             'tls_disabled': False,
  511             'trust_id': '',
  512             'trustee_domain_id': 'trustee_domain_id',
  513             'trustee_password': 'fake_trustee_password',
  514             'trustee_user_id': '7b489f04-b458-4541-8179-6a48a553e656',
  515             'trustee_username': 'fake_trustee',
  516             'username': 'fake_user',
  517             'verify_ca': True,
  518             'openstack_ca': '',
  519             "nodes_affinity_policy": "soft-anti-affinity",
  520             'availability_zone': 'az_1',
  521             'cert_manager_api': 'False',
  522             'ingress_controller': 'i-controller',
  523             'ingress_controller_role': 'i-controller-role',
  524             'octavia_ingress_controller_tag': None,
  525             'kubelet_options': '--kubelet',
  526             'kubeapi_options': '--kubeapi',
  527             'kubecontroller_options': '--kubecontroller',
  528             'kubescheduler_options': '--kubescheduler',
  529             'kubeproxy_options': '--kubeproxy',
  530             'octavia_enabled': False,
  531             'kube_service_account_key': 'public_key',
  532             'kube_service_account_private_key': 'private_key',
  533             'portal_network_cidr': '10.254.0.0/16',
  534             'project_id': 'project_id',
  535             'max_node_count': '2',
  536         }
  537         self.assertEqual(expected, definition)
  538         self.assertEqual(
  539             ['../../common/templates/environments/with_private_network.yaml',
  540              '../../common/templates/environments/no_etcd_volume.yaml',
  541              '../../common/templates/environments/with_volume.yaml',
  542              '../../common/templates/environments/no_master_lb.yaml',
  543              '../../common/templates/environments/disable_floating_ip.yaml',
  544              '../../common/templates/environments/disable_lb_floating_ip.yaml'
  545              ],
  546             env_files)
  547 
  548     @patch('requests.get')
  549     @patch('magnum.objects.ClusterTemplate.get_by_uuid')
  550     @patch('magnum.drivers.common.driver.Driver.get_driver')
  551     def test_extract_template_definition_coreos_with_disovery(
  552             self,
  553             mock_driver,
  554             mock_objects_cluster_template_get_by_uuid,
  555             mock_get):
  556         self.cluster_template_dict['cluster_distro'] = 'coreos'
  557         cluster_template = objects.ClusterTemplate(
  558             self.context, **self.cluster_template_dict)
  559         mock_objects_cluster_template_get_by_uuid.return_value = \
  560             cluster_template
  561         expected_result = str('{"action":"get","node":{"key":"test","value":'
  562                               '"1","modifiedIndex":10,"createdIndex":10}}')
  563         mock_resp = mock.MagicMock()
  564         mock_resp.text = expected_result
  565         mock_resp.status_code = 200
  566         mock_get.return_value = mock_resp
  567         cluster = objects.Cluster(self.context, **self.cluster_dict)
  568         mock_driver.return_value = k8s_coreos_dr.Driver()
  569 
  570         (template_path,
  571          definition,
  572          env_files) = mock_driver()._extract_template_definition(self.context,
  573                                                                  cluster)
  574 
  575         expected = {
  576             'ssh_key_name': 'keypair_id',
  577             'external_network': 'e2a6c8b0-a3c2-42a3-b3f4-01400a30896e',
  578             'fixed_network': 'fixed_network',
  579             'fixed_subnet': 'fixed_subnet',
  580             'availability_zone': 'az_1',
  581             'nodes_affinity_policy': 'soft-anti-affinity',
  582             'dns_nameserver': 'dns_nameserver',
  583             'docker_storage_driver': 'devicemapper',
  584             'docker_volume_size': 20,
  585             'docker_volume_type': 'lvmdriver-1',
  586             'server_image': 'image_id',
  587             'minion_flavor': 'flavor_id',
  588             'master_flavor': 'master_flavor_id',
  589             'number_of_minions': 1,
  590             'number_of_masters': 1,
  591             'network_driver': 'network_driver',
  592             'volume_driver': 'volume_driver',
  593             'discovery_url': 'https://discovery.etcd.io/test',
  594             'etcd_volume_size': None,
  595             'http_proxy': 'http_proxy',
  596             'https_proxy': 'https_proxy',
  597             'no_proxy': 'no_proxy',
  598             'flannel_network_cidr': '10.101.0.0/16',
  599             'flannel_network_subnetlen': '26',
  600             'flannel_backend': 'vxlan',
  601             'system_pods_initial_delay': '15',
  602             'system_pods_timeout': '1',
  603             'admission_control_list': 'fake_list',
  604             'prometheus_monitoring': 'False',
  605             'region_name': 'RegionOne',
  606             'grafana_admin_passwd': 'fake_pwd',
  607             'kube_dashboard_enabled': 'True',
  608             'influx_grafana_dashboard_enabled': 'True',
  609             'tls_disabled': False,
  610             'registry_enabled': False,
  611             'trustee_domain_id': self.mock_keystone.trustee_domain_id,
  612             'trustee_username': 'fake_trustee',
  613             'trustee_password': 'fake_trustee_password',
  614             'trustee_user_id': '7b489f04-b458-4541-8179-6a48a553e656',
  615             'username': 'fake_user',
  616             'trust_id': '',
  617             'auth_url': 'http://192.168.10.10:5000/v3',
  618             'cluster_uuid': self.cluster_dict['uuid'],
  619             'magnum_url': self.mock_osc.magnum_url.return_value,
  620             'insecure_registry_url': '10.0.0.1:5000',
  621             'kube_version': 'fake-version',
  622             'verify_ca': True,
  623             'openstack_ca': '',
  624             'openstack_ca_coreos': '',
  625             'cert_manager_api': 'False',
  626             'ingress_controller': 'i-controller',
  627             'ingress_controller_role': 'i-controller-role',
  628             'octavia_ingress_controller_tag': None,
  629             'kubelet_options': '--kubelet',
  630             'kubeapi_options': '--kubeapi',
  631             'kubecontroller_options': '--kubecontroller',
  632             'kubescheduler_options': '--kubescheduler',
  633             'kubeproxy_options': '--kubeproxy',
  634             'octavia_enabled': False,
  635             'portal_network_cidr': '10.254.0.0/16',
  636         }
  637         self.assertEqual(expected, definition)
  638         self.assertEqual(
  639             ['../../common/templates/environments/no_private_network.yaml',
  640              '../../common/templates/environments/no_etcd_volume.yaml',
  641              '../../common/templates/environments/with_volume.yaml',
  642              '../../common/templates/environments/no_master_lb.yaml',
  643              '../../common/templates/environments/disable_floating_ip.yaml',
  644              '../../common/templates/environments/disable_lb_floating_ip.yaml'
  645              ],
  646             env_files)
  647 
  648     @patch('requests.get')
  649     @patch('magnum.objects.ClusterTemplate.get_by_uuid')
  650     @patch('magnum.drivers.common.driver.Driver.get_driver')
  651     def test_extract_template_definition_coreos_no_discoveryurl(
  652             self,
  653             mock_driver,
  654             mock_objects_cluster_template_get_by_uuid,
  655             reqget):
  656         self.cluster_template_dict['cluster_distro'] = 'coreos'
  657         self.cluster_dict['discovery_url'] = None
  658         mock_req = mock.MagicMock(text='http://tokentest/h1/h2/h3',
  659                                   status_code=200)
  660         reqget.return_value = mock_req
  661         cluster_template = objects.ClusterTemplate(
  662             self.context, **self.cluster_template_dict)
  663         mock_objects_cluster_template_get_by_uuid.return_value = \
  664             cluster_template
  665         cluster = objects.Cluster(self.context, **self.cluster_dict)
  666         mock_driver.return_value = k8s_coreos_dr.Driver()
  667 
  668         (template_path,
  669          definition,
  670          env_files) = mock_driver()._extract_template_definition(self.context,
  671                                                                  cluster)
  672 
  673         expected = {
  674             'ssh_key_name': 'keypair_id',
  675             'availability_zone': 'az_1',
  676             'external_network': 'e2a6c8b0-a3c2-42a3-b3f4-01400a30896e',
  677             'fixed_network': 'fixed_network',
  678             'fixed_subnet': 'fixed_subnet',
  679             'dns_nameserver': 'dns_nameserver',
  680             'docker_storage_driver': u'devicemapper',
  681             'docker_volume_size': 20,
  682             'docker_volume_type': u'lvmdriver-1',
  683             'server_image': 'image_id',
  684             'minion_flavor': 'flavor_id',
  685             'master_flavor': 'master_flavor_id',
  686             'number_of_minions': 1,
  687             'number_of_masters': 1,
  688             'network_driver': 'network_driver',
  689             'volume_driver': 'volume_driver',
  690             'discovery_url': 'http://tokentest/h1/h2/h3',
  691             'etcd_volume_size': None,
  692             'http_proxy': 'http_proxy',
  693             'https_proxy': 'https_proxy',
  694             'no_proxy': 'no_proxy',
  695             'nodes_affinity_policy': 'soft-anti-affinity',
  696             'flannel_network_cidr': '10.101.0.0/16',
  697             'flannel_network_subnetlen': '26',
  698             'flannel_backend': 'vxlan',
  699             'system_pods_initial_delay': '15',
  700             'system_pods_timeout': '1',
  701             'admission_control_list': 'fake_list',
  702             'prometheus_monitoring': 'False',
  703             'region_name': self.mock_osc.cinder_region_name.return_value,
  704             'grafana_admin_passwd': 'fake_pwd',
  705             'kube_dashboard_enabled': 'True',
  706             'influx_grafana_dashboard_enabled': 'True',
  707             'tls_disabled': False,
  708             'registry_enabled': False,
  709             'trustee_domain_id': self.mock_keystone.trustee_domain_id,
  710             'trustee_username': 'fake_trustee',
  711             'username': 'fake_user',
  712             'trustee_password': 'fake_trustee_password',
  713             'trustee_user_id': '7b489f04-b458-4541-8179-6a48a553e656',
  714             'trust_id': '',
  715             'auth_url': 'http://192.168.10.10:5000/v3',
  716             'cluster_uuid': self.cluster_dict['uuid'],
  717             'magnum_url': self.mock_osc.magnum_url.return_value,
  718             'insecure_registry_url': '10.0.0.1:5000',
  719             'kube_version': 'fake-version',
  720             'verify_ca': True,
  721             'openstack_ca': '',
  722             'openstack_ca_coreos': '',
  723             'cert_manager_api': 'False',
  724             'ingress_controller': 'i-controller',
  725             'ingress_controller_role': 'i-controller-role',
  726             'octavia_ingress_controller_tag': None,
  727             'kubelet_options': '--kubelet',
  728             'kubeapi_options': '--kubeapi',
  729             'kubecontroller_options': '--kubecontroller',
  730             'kubescheduler_options': '--kubescheduler',
  731             'kubeproxy_options': '--kubeproxy',
  732             'octavia_enabled': False,
  733             'portal_network_cidr': '10.254.0.0/16',
  734         }
  735         self.assertEqual(expected, definition)
  736         self.assertEqual(
  737             ['../../common/templates/environments/no_private_network.yaml',
  738              '../../common/templates/environments/no_etcd_volume.yaml',
  739              '../../common/templates/environments/with_volume.yaml',
  740              '../../common/templates/environments/no_master_lb.yaml',
  741              '../../common/templates/environments/disable_floating_ip.yaml',
  742              '../../common/templates/environments/disable_lb_floating_ip.yaml'
  743              ],
  744             env_files)
  745 
  746     @patch('requests.get')
  747     @patch('magnum.objects.ClusterTemplate.get_by_uuid')
  748     @patch('magnum.drivers.common.driver.Driver.get_driver')
  749     @patch('magnum.conductor.handlers.common.cert_manager'
  750            '.sign_node_certificate')
  751     @patch('magnum.common.x509.operations.generate_csr_and_key')
  752     def test_extract_template_definition_without_dns(
  753             self,
  754             mock_generate_csr_and_key,
  755             mock_sign_node_certificate,
  756             mock_driver,
  757             mock_objects_cluster_template_get_by_uuid,
  758             mock_get):
  759         mock_driver.return_value = k8s_dr.Driver()
  760         self._test_extract_template_definition(
  761             mock_generate_csr_and_key,
  762             mock_sign_node_certificate,
  763             mock_driver,
  764             mock_objects_cluster_template_get_by_uuid,
  765             mock_get,
  766             missing_attr='dns_nameserver')
  767 
  768     @patch('requests.get')
  769     @patch('magnum.objects.ClusterTemplate.get_by_uuid')
  770     @patch('magnum.drivers.common.driver.Driver.get_driver')
  771     @patch('magnum.conductor.handlers.common.cert_manager'
  772            '.sign_node_certificate')
  773     @patch('magnum.common.x509.operations.generate_csr_and_key')
  774     def test_extract_template_definition_without_server_image(
  775             self,
  776             mock_generate_csr_and_key,
  777             mock_sign_node_certificate,
  778             mock_driver,
  779             mock_objects_cluster_template_get_by_uuid,
  780             mock_get):
  781         mock_driver.return_value = k8s_dr.Driver()
  782         self._test_extract_template_definition(
  783             mock_generate_csr_and_key,
  784             mock_sign_node_certificate,
  785             mock_driver,
  786             mock_objects_cluster_template_get_by_uuid,
  787             mock_get,
  788             missing_attr='image_id')
  789 
  790     @patch('requests.get')
  791     @patch('magnum.objects.ClusterTemplate.get_by_uuid')
  792     @patch('magnum.drivers.common.driver.Driver.get_driver')
  793     @patch('magnum.conductor.handlers.common.cert_manager'
  794            '.sign_node_certificate')
  795     @patch('magnum.common.x509.operations.generate_csr_and_key')
  796     def test_extract_template_definition_without_docker_storage_driver(
  797             self,
  798             mock_generate_csr_and_key,
  799             mock_sign_node_certificate,
  800             mock_driver,
  801             mock_objects_cluster_template_get_by_uuid,
  802             mock_get):
  803         mock_driver.return_value = k8s_dr.Driver()
  804         self._test_extract_template_definition(
  805             mock_generate_csr_and_key,
  806             mock_sign_node_certificate,
  807             mock_driver,
  808             mock_objects_cluster_template_get_by_uuid,
  809             mock_get,
  810             missing_attr='docker_storage_driver')
  811 
  812     @patch('requests.get')
  813     @patch('magnum.objects.ClusterTemplate.get_by_uuid')
  814     @patch('magnum.drivers.common.driver.Driver.get_driver')
  815     @patch('magnum.conductor.handlers.common.cert_manager'
  816            '.sign_node_certificate')
  817     @patch('magnum.common.x509.operations.generate_csr_and_key')
  818     def test_extract_template_definition_without_apiserver_port(
  819             self,
  820             mock_generate_csr_and_key,
  821             mock_sign_node_certificate,
  822             mock_driver,
  823             mock_objects_cluster_template_get_by_uuid,
  824             mock_get):
  825         mock_driver.return_value = k8s_dr.Driver()
  826         self._test_extract_template_definition(
  827             mock_generate_csr_and_key,
  828             mock_sign_node_certificate,
  829             mock_driver,
  830             mock_objects_cluster_template_get_by_uuid,
  831             mock_get,
  832             missing_attr='apiserver_port')
  833 
  834     @patch('requests.get')
  835     @patch('magnum.objects.ClusterTemplate.get_by_uuid')
  836     @patch('magnum.drivers.common.driver.Driver.get_driver')
  837     @patch('magnum.conductor.handlers.common.cert_manager'
  838            '.sign_node_certificate')
  839     @patch('magnum.common.x509.operations.generate_csr_and_key')
  840     def test_extract_template_definition_without_node_count(
  841             self,
  842             mock_generate_csr_and_key,
  843             mock_sign_node_certificate,
  844             mock_driver,
  845             mock_objects_cluster_template_get_by_uuid,
  846             mock_get):
  847         mock_driver.return_value = k8s_dr.Driver()
  848         self._test_extract_template_definition(
  849             mock_generate_csr_and_key,
  850             mock_sign_node_certificate,
  851             mock_driver,
  852             mock_objects_cluster_template_get_by_uuid,
  853             mock_get,
  854             missing_attr='node_count')
  855 
  856     @patch('requests.get')
  857     @patch('magnum.objects.ClusterTemplate.get_by_uuid')
  858     @patch('magnum.drivers.common.driver.Driver.get_driver')
  859     @patch('magnum.conductor.handlers.common.cert_manager'
  860            '.sign_node_certificate')
  861     @patch('magnum.common.x509.operations.generate_csr_and_key')
  862     def test_extract_template_definition_without_master_count(
  863             self,
  864             mock_generate_csr_and_key,
  865             mock_sign_node_certificate,
  866             mock_driver,
  867             mock_objects_cluster_template_get_by_uuid,
  868             mock_get):
  869         mock_driver.return_value = k8s_dr.Driver()
  870         self._test_extract_template_definition(
  871             mock_generate_csr_and_key,
  872             mock_sign_node_certificate,
  873             mock_driver,
  874             mock_objects_cluster_template_get_by_uuid,
  875             mock_get,
  876             missing_attr='master_count')
  877 
  878     @patch('requests.get')
  879     @patch('magnum.objects.ClusterTemplate.get_by_uuid')
  880     @patch('magnum.drivers.common.driver.Driver.get_driver')
  881     @patch('magnum.conductor.handlers.common.cert_manager'
  882            '.sign_node_certificate')
  883     @patch('magnum.common.x509.operations.generate_csr_and_key')
  884     def test_extract_template_definition_without_discovery_url(
  885             self,
  886             mock_generate_csr_and_key,
  887             mock_sign_node_certificate,
  888             mock_driver,
  889             mock_objects_cluster_template_get_by_uuid,
  890             reqget):
  891         cluster_template = objects.ClusterTemplate(
  892             self.context, **self.cluster_template_dict)
  893         mock_generate_csr_and_key.return_value = {'csr': 'csr',
  894                                                   'private_key': 'private_key',
  895                                                   'public_key': 'public_key'}
  896         mock_sign_node_certificate.return_value = 'signed_cert'
  897         mock_objects_cluster_template_get_by_uuid.return_value = \
  898             cluster_template
  899         cluster_dict = self.cluster_dict
  900         cluster_dict['discovery_url'] = None
  901         cluster = objects.Cluster(self.context, **cluster_dict)
  902         mock_driver.return_value = k8s_dr.Driver()
  903 
  904         CONF.set_override('etcd_discovery_service_endpoint_format',
  905                           'http://etcd/test?size=%(size)d',
  906                           group='cluster')
  907         mock_req = mock.MagicMock(text='https://address/token',
  908                                   status_code=200)
  909         reqget.return_value = mock_req
  910 
  911         (template_path,
  912          definition,
  913          env_files) = mock_driver()._extract_template_definition(self.context,
  914                                                                  cluster)
  915 
  916         expected = {
  917             'cloud_provider_enabled': 'false',
  918             'ssh_key_name': 'keypair_id',
  919             'external_network': 'e2a6c8b0-a3c2-42a3-b3f4-01400a30896e',
  920             'fixed_network': 'fixed_network',
  921             'fixed_subnet': 'fixed_subnet',
  922             'dns_nameserver': 'dns_nameserver',
  923             'server_image': 'image_id',
  924             'master_flavor': 'master_flavor_id',
  925             'minion_flavor': 'flavor_id',
  926             'number_of_minions': 1,
  927             'number_of_masters': 1,
  928             'network_driver': 'network_driver',
  929             'volume_driver': 'volume_driver',
  930             'docker_volume_size': 20,
  931             'docker_volume_type': 'lvmdriver-1',
  932             'docker_storage_driver': 'devicemapper',
  933             'discovery_url': 'https://address/token',
  934             'etcd_volume_size': None,
  935             'http_proxy': 'http_proxy',
  936             'https_proxy': 'https_proxy',
  937             'no_proxy': 'no_proxy',
  938             'flannel_network_cidr': '10.101.0.0/16',
  939             'flannel_network_subnetlen': '26',
  940             'flannel_backend': 'vxlan',
  941             'system_pods_initial_delay': '15',
  942             'system_pods_timeout': '1',
  943             'admission_control_list': 'fake_list',
  944             'prometheus_monitoring': 'False',
  945             'grafana_admin_passwd': 'fake_pwd',
  946             'kube_dashboard_enabled': 'True',
  947             'influx_grafana_dashboard_enabled': 'True',
  948             'username': 'fake_user',
  949             'cluster_uuid': self.cluster_dict['uuid'],
  950             'magnum_url': self.mock_osc.magnum_url.return_value,
  951             'region_name': self.mock_osc.cinder_region_name.return_value,
  952             'tls_disabled': False,
  953             'registry_enabled': False,
  954             'trustee_domain_id': self.mock_keystone.trustee_domain_id,
  955             'trustee_username': 'fake_trustee',
  956             'trustee_password': 'fake_trustee_password',
  957             'trustee_user_id': '7b489f04-b458-4541-8179-6a48a553e656',
  958             'trust_id': '',
  959             'auth_url': 'http://192.168.10.10:5000/v3',
  960             'insecure_registry_url': '10.0.0.1:5000',
  961             'kube_version': 'fake-version',
  962             'verify_ca': True,
  963             'openstack_ca': '',
  964             "nodes_affinity_policy": "soft-anti-affinity",
  965             'availability_zone': 'az_1',
  966             'cert_manager_api': 'False',
  967             'ingress_controller': 'i-controller',
  968             'ingress_controller_role': 'i-controller-role',
  969             'octavia_ingress_controller_tag': None,
  970             'kubelet_options': '--kubelet',
  971             'kubeapi_options': '--kubeapi',
  972             'kubecontroller_options': '--kubecontroller',
  973             'kubescheduler_options': '--kubescheduler',
  974             'kubeproxy_options': '--kubeproxy',
  975             'octavia_enabled': False,
  976             'kube_service_account_key': 'public_key',
  977             'kube_service_account_private_key': 'private_key',
  978             'portal_network_cidr': '10.254.0.0/16',
  979             'project_id': 'project_id',
  980             'max_node_count': '2',
  981         }
  982         self.assertEqual(expected, definition)
  983         self.assertEqual(
  984             ['../../common/templates/environments/no_private_network.yaml',
  985              '../../common/templates/environments/no_etcd_volume.yaml',
  986              '../../common/templates/environments/with_volume.yaml',
  987              '../../common/templates/environments/no_master_lb.yaml',
  988              '../../common/templates/environments/disable_floating_ip.yaml',
  989              '../../common/templates/environments/disable_lb_floating_ip.yaml',
  990              ],
  991             env_files)
  992         reqget.assert_called_once_with('http://etcd/test?size=1')
  993 
  994     @patch('magnum.common.short_id.generate_id')
  995     @patch('heatclient.common.template_utils.get_template_contents')
  996     @patch('magnum.drivers.k8s_fedora_atomic_v1.driver.Driver.'
  997            '_extract_template_definition')
  998     @patch('magnum.common.clients.OpenStackClients')
  999     def test_create_stack(self,
 1000                           mock_osc,
 1001                           mock_extract_template_definition,
 1002                           mock_get_template_contents,
 1003                           mock_generate_id):
 1004 
 1005         mock_generate_id.return_value = 'xx-xx-xx-xx'
 1006         expected_stack_name = 'expected-stack-name-xx-xx-xx-xx'
 1007         expected_template_contents = 'template_contents'
 1008         dummy_cluster_name = 'expected_stack_name'
 1009         expected_timeout = 15
 1010 
 1011         mock_tpl_files = {}
 1012         mock_get_template_contents.return_value = [
 1013             mock_tpl_files, expected_template_contents]
 1014         mock_extract_template_definition.return_value = ('template/path',
 1015                                                          {}, [])
 1016         mock_heat_client = mock.MagicMock()
 1017         mock_osc.return_value.heat.return_value = mock_heat_client
 1018         mock_cluster = mock.MagicMock()
 1019         mock_cluster.name = dummy_cluster_name
 1020 
 1021         k8s_dr.Driver().create_cluster(self.context, mock_cluster,
 1022                                        expected_timeout)
 1023 
 1024         expected_args = {
 1025             'stack_name': expected_stack_name,
 1026             'parameters': {},
 1027             'template': expected_template_contents,
 1028             'files': {},
 1029             'environment_files': [],
 1030             'timeout_mins': expected_timeout
 1031         }
 1032         mock_heat_client.stacks.create.assert_called_once_with(**expected_args)
 1033 
 1034     @patch('magnum.common.short_id.generate_id')
 1035     @patch('heatclient.common.template_utils.get_template_contents')
 1036     @patch('magnum.drivers.k8s_fedora_atomic_v1.driver.Driver.'
 1037            '_extract_template_definition')
 1038     @patch('magnum.common.clients.OpenStackClients')
 1039     def test_create_stack_no_timeout_specified(
 1040             self,
 1041             mock_osc,
 1042             mock_extract_template_definition,
 1043             mock_get_template_contents,
 1044             mock_generate_id):
 1045 
 1046         mock_generate_id.return_value = 'xx-xx-xx-xx'
 1047         expected_stack_name = 'expected-stack-name-xx-xx-xx-xx'
 1048         expected_template_contents = 'template_contents'
 1049         dummy_cluster_name = 'expected_stack_name'
 1050         expected_timeout = CONF.cluster_heat.create_timeout
 1051 
 1052         mock_tpl_files = {}
 1053         mock_get_template_contents.return_value = [
 1054             mock_tpl_files, expected_template_contents]
 1055         mock_extract_template_definition.return_value = ('template/path',
 1056                                                          {}, [])
 1057         mock_heat_client = mock.MagicMock()
 1058         mock_osc.return_value.heat.return_value = mock_heat_client
 1059         mock_cluster = mock.MagicMock()
 1060         mock_cluster.name = dummy_cluster_name
 1061 
 1062         k8s_dr.Driver().create_cluster(self.context, mock_cluster, None)
 1063 
 1064         expected_args = {
 1065             'stack_name': expected_stack_name,
 1066             'parameters': {},
 1067             'template': expected_template_contents,
 1068             'files': {},
 1069             'environment_files': [],
 1070             'timeout_mins': expected_timeout
 1071         }
 1072         mock_heat_client.stacks.create.assert_called_once_with(**expected_args)
 1073 
 1074     @patch('magnum.common.short_id.generate_id')
 1075     @patch('heatclient.common.template_utils.get_template_contents')
 1076     @patch('magnum.drivers.k8s_fedora_atomic_v1.driver.Driver.'
 1077            '_extract_template_definition')
 1078     @patch('magnum.common.clients.OpenStackClients')
 1079     def test_create_stack_timeout_is_zero(
 1080             self,
 1081             mock_osc,
 1082             mock_extract_template_definition,
 1083             mock_get_template_contents,
 1084             mock_generate_id):
 1085 
 1086         mock_generate_id.return_value = 'xx-xx-xx-xx'
 1087         expected_stack_name = 'expected-stack-name-xx-xx-xx-xx'
 1088         expected_template_contents = 'template_contents'
 1089         dummy_cluster_name = 'expected_stack_name'
 1090         cluster_timeout = 0
 1091         expected_timeout = CONF.cluster_heat.create_timeout
 1092 
 1093         mock_tpl_files = {}
 1094         mock_get_template_contents.return_value = [
 1095             mock_tpl_files, expected_template_contents]
 1096         mock_extract_template_definition.return_value = ('template/path',
 1097                                                          {}, [])
 1098         mock_heat_client = mock.MagicMock()
 1099         mock_osc.return_value.heat.return_value = mock_heat_client
 1100         mock_cluster = mock.MagicMock()
 1101         mock_cluster.name = dummy_cluster_name
 1102 
 1103         k8s_dr.Driver().create_cluster(self.context, mock_cluster,
 1104                                        cluster_timeout)
 1105 
 1106         expected_args = {
 1107             'stack_name': expected_stack_name,
 1108             'parameters': {},
 1109             'template': expected_template_contents,
 1110             'files': {},
 1111             'environment_files': [],
 1112             'timeout_mins': expected_timeout
 1113         }
 1114         mock_heat_client.stacks.create.assert_called_once_with(**expected_args)
 1115 
 1116     @patch('heatclient.common.template_utils.get_template_contents')
 1117     @patch('magnum.drivers.k8s_fedora_atomic_v1.driver.Driver.'
 1118            '_extract_template_definition')
 1119     @patch('magnum.common.clients.OpenStackClients')
 1120     def test_update_stack(self,
 1121                           mock_osc,
 1122                           mock_extract_template_definition,
 1123                           mock_get_template_contents):
 1124 
 1125         mock_stack_id = 'xx-xx-xx-xx'
 1126         mock_heat_client = mock.MagicMock()
 1127         mock_osc.return_value.heat.return_value = mock_heat_client
 1128         mock_cluster = mock.MagicMock()
 1129         mock_cluster.stack_id = mock_stack_id
 1130 
 1131         k8s_dr.Driver().update_cluster({}, mock_cluster)
 1132 
 1133         expected_args = {
 1134             'parameters': {'number_of_minions': mock_cluster.node_count},
 1135             'existing': True,
 1136             'disable_rollback': True
 1137         }
 1138         mock_heat_client.stacks.update.assert_called_once_with(mock_stack_id,
 1139                                                                **expected_args)