Beispiel #1
0
    def _test_enforce_volume_driver_types_update(self,
                                                 mock_get_resource,
                                                 mock_pecan_request,
                                                 volume_driver_type,
                                                 op,
                                                 assert_raised=False):
        @v.enforce_volume_driver_types_update()
        def test(self, cluster_template_ident, patch):
            pass

        cluster_template_ident = 'test_uuid_or_name'
        patch = [{
            'path': '/volume_driver',
            'value': volume_driver_type,
            'op': op
        }]
        context = mock_pecan_request.context
        cluster_template = obj_utils.get_test_cluster_template(
            context, uuid=cluster_template_ident, coe='kubernetes')
        mock_get_resource.return_value = cluster_template

        # Reload the validator module so that ClusterTemplate configs are
        # re-evaluated.
        reload_module(v)
        validator = v.K8sValidator
        validator.supported_volume_driver = ['cinder']

        if assert_raised:
            self.assertRaises(exception.InvalidParameterValue, test, self,
                              cluster_template_ident, patch)
        else:
            test(self, cluster_template_ident, patch)
            mock_get_resource.assert_called_once_with('ClusterTemplate',
                                                      cluster_template_ident)
Beispiel #2
0
 def test_create_monitor_k8s_cluster(self):
     self.cluster.cluster_template = obj_utils.get_test_cluster_template(
         self.context,
         uuid=self.cluster.cluster_template_id,
         coe='kubernetes')
     monitor = monitors.create_monitor(self.context, self.cluster)
     self.assertIsInstance(monitor, k8s_monitor.K8sMonitor)
Beispiel #3
0
    def _test_enforce_bay_types(self,
                                mock_bay_get_by_uuid,
                                mock_pecan_request,
                                bay_type,
                                allowed_bay_types,
                                assert_raised=False,
                                *args):
        @v.enforce_bay_types(*allowed_bay_types)
        def test(self, *args):
            if hasattr(args[0], 'bay_uuid'):
                return args[0].name
            else:
                return args[1]

        context = mock_pecan_request.context
        bay = mock.MagicMock()
        bay.baymodel_id = 'cluster_template_id'
        cluster_template = obj_utils.get_test_cluster_template(
            context, uuid='cluster_template_id', coe=bay_type)
        bay.cluster_template = cluster_template

        mock_bay_get_by_uuid.return_value = bay

        if assert_raised:
            self.assertRaises(exception.InvalidParameterValue, test, self,
                              *args)
        else:
            ret = test(self, *args)
            if hasattr(args[0], 'bay_uuid'):
                mock_bay_get_by_uuid.assert_called_once_with(
                    context, args[0].bay_uuid)
                self.assertEqual(args[0].name, ret)
            else:
                mock_bay_get_by_uuid.assert_called_once_with(context, args[1])
                self.assertEqual(args[1], ret)
Beispiel #4
0
    def _test_enforce_cluster_type_supported(self,
                                             mock_cluster_template_get_by_uuid,
                                             mock_cluster_get_by_uuid,
                                             mock_pecan_request,
                                             cluster_type,
                                             assert_raised=False):
        @v.enforce_cluster_type_supported()
        def test(self, cluster):
            pass

        server_type, cluster_distro, coe = cluster_type
        cluster_template = obj_utils.get_test_cluster_template(
            mock_pecan_request.context,
            uuid='cluster_template_id',
            coe=coe,
            cluster_distro=cluster_distro,
            server_type=server_type)
        mock_cluster_template_get_by_uuid.return_value = cluster_template

        cluster = mock.MagicMock()
        cluster.cluster_template_id = 'cluster_template_id'
        cluster.cluster_template = cluster_template
        mock_cluster_get_by_uuid.return_value = cluster

        if assert_raised:
            return self.assertRaises(exception.ClusterTypeNotSupported, test,
                                     self, cluster)
        else:
            self.assertIsNone(test(self, cluster))
Beispiel #5
0
    def _test_enforce_volume_driver_types_update(
            self,
            mock_get_resource,
            mock_pecan_request,
            volume_driver_type,
            op,
            assert_raised=False):

        @v.enforce_volume_driver_types_update()
        def test(self, cluster_template_ident, patch):
            pass

        cluster_template_ident = 'test_uuid_or_name'
        patch = [{'path': '/volume_driver', 'value': volume_driver_type,
                  'op': op}]
        context = mock_pecan_request.context
        cluster_template = obj_utils.get_test_cluster_template(
            context, uuid=cluster_template_ident, coe='kubernetes')
        mock_get_resource.return_value = cluster_template

        # Reload the validator module so that ClusterTemplate configs are
        # re-evaluated.
        reload_module(v)
        validator = v.K8sValidator
        validator.supported_volume_driver = ['cinder']

        if assert_raised:
            self.assertRaises(exception.InvalidParameterValue,
                              test, self, cluster_template_ident, patch)
        else:
            test(self, cluster_template_ident, patch)
            mock_get_resource.assert_called_once_with(
                'ClusterTemplate', cluster_template_ident)
Beispiel #6
0
    def _test_enforce_server_type(self,
                                  server_type,
                                  coe='kubernetes',
                                  assert_raised=False):
        @v.enforce_server_type()
        def test(self, cluster_template):
            pass

        cluster_template = obj_utils.get_test_cluster_template(
            {}, name='test_cluster_template', coe=coe, server_type=server_type)

        if assert_raised:
            self.assertRaises(exception.InvalidParameterValue, test, self,
                              cluster_template)
        else:
            test(self, cluster_template)
Beispiel #7
0
    def _test_enforce_server_type(
            self,
            server_type,
            coe='kubernetes',
            assert_raised=False):

        @v.enforce_server_type()
        def test(self, cluster_template):
            pass

        cluster_template = obj_utils.get_test_cluster_template(
            {}, name='test_cluster_template', coe=coe,
            server_type=server_type)

        if assert_raised:
            self.assertRaises(exception.InvalidParameterValue,
                              test, self, cluster_template)
        else:
            test(self, cluster_template)
Beispiel #8
0
    def _test_enforce_network_driver_types_update(self,
                                                  mock_get_resource,
                                                  mock_pecan_request,
                                                  network_driver_type,
                                                  network_driver_config_dict,
                                                  assert_raised=False):
        @v.enforce_network_driver_types_update()
        def test(self, cluster_template_ident, patch):
            pass

        for key, val in network_driver_config_dict.items():
            cfg.CONF.set_override(key, val, 'cluster_template')

        cluster_template_ident = 'test_uuid_or_name'

        patch = [{
            'path': '/network_driver',
            'value': network_driver_type,
            'op': 'replace'
        }]
        context = mock_pecan_request.context
        cluster_template = obj_utils.get_test_cluster_template(
            context, uuid=cluster_template_ident, coe='kubernetes')
        cluster_template.network_driver = network_driver_type
        mock_get_resource.return_value = cluster_template

        # Reload the validator module so that ClusterTemplate configs are
        # re-evaluated.
        reload_module(v)
        validator = v.K8sValidator
        validator.supported_network_drivers = ['flannel', 'type1', 'type2']

        if assert_raised:
            self.assertRaises(exception.InvalidParameterValue, test, self,
                              cluster_template_ident, patch)
        else:
            test(self, cluster_template_ident, patch)
            mock_get_resource.assert_called_once_with('ClusterTemplate',
                                                      cluster_template_ident)
Beispiel #9
0
    def _test_enforce_cluster_types(
            self,
            mock_cluster_get_by_uuid,
            mock_pecan_request,
            cluster_type,
            allowed_cluster_types,
            assert_raised=False,
            *args):

        @v.enforce_cluster_types(*allowed_cluster_types)
        def test(self, *args):
            if hasattr(args[0], 'cluster_uuid'):
                return args[0].name
            else:
                return args[1]

        context = mock_pecan_request.context
        cluster = mock.MagicMock()
        cluster.cluster_template_id = 'cluster_template_id'
        cluster_template = obj_utils.get_test_cluster_template(
            context, uuid='cluster_template_id', coe=cluster_type)
        cluster.cluster_template = cluster_template

        mock_cluster_get_by_uuid.return_value = cluster

        if assert_raised:
            self.assertRaises(
                exception.InvalidParameterValue, test, self, *args)
        else:
            ret = test(self, *args)
            if hasattr(args[0], 'cluster_uuid'):
                mock_cluster_get_by_uuid.assert_called_once_with(
                    context, args[0].cluster_uuid)
                self.assertEqual(args[0].name, ret)
            else:
                mock_cluster_get_by_uuid.assert_called_once_with(
                    context, args[1])
                self.assertEqual(args[1], ret)
Beispiel #10
0
    def _test_enforce_network_driver_types_update(
            self,
            mock_get_resource,
            mock_pecan_request,
            network_driver_type,
            network_driver_config_dict,
            assert_raised=False):

        @v.enforce_network_driver_types_update()
        def test(self, cluster_template_ident, patch):
            pass

        for key, val in network_driver_config_dict.items():
            CONF.set_override(key, val, 'cluster_template')

        cluster_template_ident = 'test_uuid_or_name'

        patch = [{'path': '/network_driver', 'value': network_driver_type,
                  'op': 'replace'}]
        context = mock_pecan_request.context
        cluster_template = obj_utils.get_test_cluster_template(
            context, uuid=cluster_template_ident, coe='kubernetes')
        cluster_template.network_driver = network_driver_type
        mock_get_resource.return_value = cluster_template

        # Reload the validator module so that ClusterTemplate configs are
        # re-evaluated.
        reload_module(v)
        validator = v.K8sValidator
        validator.supported_network_drivers = ['flannel', 'type1', 'type2']

        if assert_raised:
            self.assertRaises(exception.InvalidParameterValue,
                              test, self, cluster_template_ident, patch)
        else:
            test(self, cluster_template_ident, patch)
            mock_get_resource.assert_called_once_with(
                'ClusterTemplate', cluster_template_ident)
Beispiel #11
0
    def _test_enforce_cluster_type_supported(
            self, mock_cluster_template_get_by_uuid, mock_cluster_get_by_uuid,
            mock_pecan_request, cluster_type, assert_raised=False):

        @v.enforce_cluster_type_supported()
        def test(self, cluster):
            pass

        server_type, cluster_distro, coe = cluster_type
        cluster_template = obj_utils.get_test_cluster_template(
            mock_pecan_request.context, uuid='cluster_template_id',
            coe=coe, cluster_distro=cluster_distro, server_type=server_type)
        mock_cluster_template_get_by_uuid.return_value = cluster_template

        cluster = mock.MagicMock()
        cluster.cluster_template_id = 'cluster_template_id'
        cluster.cluster_template = cluster_template
        mock_cluster_get_by_uuid.return_value = cluster

        if assert_raised:
            return self.assertRaises(
                exception.ClusterTypeNotSupported, test, self, cluster)
        else:
            self.assertIsNone(test(self, cluster))
Beispiel #12
0
 def test_create_monitor_mesos_bay(self):
     self.bay.cluster_template = obj_utils.get_test_cluster_template(
         self.context, uuid=self.bay.baymodel_id, coe='mesos')
     monitor = monitors.create_monitor(self.context, self.bay)
     self.assertIsInstance(monitor, mesos_monitor.MesosMonitor)
Beispiel #13
0
 def test_create_monitor_success(self):
     self.bay.cluster_template = obj_utils.get_test_cluster_template(
         self.context, uuid=self.bay.baymodel_id, coe='swarm')
     monitor = monitors.create_monitor(self.context, self.bay)
     self.assertIsInstance(monitor, swarm_monitor.SwarmMonitor)
Beispiel #14
0
 def test_create_monitor_mesos_cluster(self):
     self.cluster.cluster_template = obj_utils.get_test_cluster_template(
         self.context, uuid=self.cluster.cluster_template_id, coe='mesos')
     monitor = monitors.create_monitor(self.context, self.cluster)
     self.assertIsInstance(monitor, mesos_monitor.MesosMonitor)
Beispiel #15
0
 def test_create_monitor_k8s_cluster(self):
     self.cluster.cluster_template = obj_utils.get_test_cluster_template(
         self.context, uuid=self.cluster.cluster_template_id,
         coe='kubernetes')
     monitor = monitors.create_monitor(self.context, self.cluster)
     self.assertIsInstance(monitor, k8s_monitor.K8sMonitor)
Beispiel #16
0
 def test_create_monitor_success(self):
     self.cluster.cluster_template = obj_utils.get_test_cluster_template(
         self.context, uuid=self.cluster.cluster_template_id, coe='swarm')
     monitor = monitors.create_monitor(self.context, self.cluster)
     self.assertIsInstance(monitor, swarm_monitor.SwarmMonitor)