diff --git a/config/samples/operator-config.yaml b/config/samples/operator-config.yaml new file mode 100644 index 00000000..2045f809 --- /dev/null +++ b/config/samples/operator-config.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: operator-config +data: + operator-config.yaml: | + horizon: + ingress: + host: "horizon.vexxhost.com" + keystone: + configDir: /etc/keystone + heat: + configDir: /etc/heat + chronyd: {} \ No newline at end of file diff --git a/openstack_operator/tests/unit/base.py b/openstack_operator/tests/unit/base.py index 0e64c685..a770a7aa 100644 --- a/openstack_operator/tests/unit/base.py +++ b/openstack_operator/tests/unit/base.py @@ -34,22 +34,42 @@ class KubernetesObjectTestCase(testtools.TestCase): SAMPLES_PATH = 'config/samples' SAMPLE_FILE = '' TEMPLATE_FILE = '' - NAMESPACE_CHECK = True + # If auto generated, or no CR exists + AUTO_GENERATED = True + RELEASE_TYPE = '' @classmethod def setUpClass(cls): - sample_path = "%s/%s" % (cls.SAMPLES_PATH, cls.SAMPLE_FILE) - with open(sample_path) as sample_fd: - sample = yaml.load(sample_fd, Loader=yaml.FullLoader) - name = sample['metadata']['name'] - spec = sample['spec'] + if cls.AUTO_GENERATED: + config_path = "%s/%s" % (cls.SAMPLES_PATH, "operator-config.yaml") + with open(config_path) as config_fd: + sample = yaml.load(config_fd, Loader=yaml.FullLoader) + name = sample['metadata']['name'] + spec = utils.to_dict( + sample['data']['operator-config.yaml'])[cls.RELEASE_TYPE] + cls.object = utils.render_template(cls.TEMPLATE_FILE, + name=cls.RELEASE_TYPE, + spec=spec) + else: + sample_path = "%s/%s" % (cls.SAMPLES_PATH, cls.SAMPLE_FILE) + with open(sample_path) as sample_fd: + sample = yaml.load(sample_fd, Loader=yaml.FullLoader) + name = sample['metadata']['name'] + spec = sample['spec'] - cls.object = utils.render_template(cls.TEMPLATE_FILE, - name=name, spec=spec) + cls.object = utils.render_template(cls.TEMPLATE_FILE, + name=name, spec=spec) - def test_metadata_has_no_namespace(self): - """Ensure that the metadata does not specify the namespace.""" - if self.NAMESPACE_CHECK: + def auto_generation_test_metadata_has_openstack_namespace(self): + """Ensure that the metadata for auto-generated releases + has openstack namespace.""" + if self.AUTO_GENERATED: + self.assertIn("namespace", self.object["metadata"]) + self.assertEqual("openstack", self.object["metadata"]["namespace"]) + + def cr_test_metadata_has_no_specific_namespace(self): + """Ensure that the CR metadata has no specific namespace.""" + if not self.AUTO_GENERATED: self.assertNotIn("namespace", self.object["metadata"]) diff --git a/openstack_operator/tests/unit/test_heat.py b/openstack_operator/tests/unit/test_heat.py index 52d416db..3e454fba 100644 --- a/openstack_operator/tests/unit/test_heat.py +++ b/openstack_operator/tests/unit/test_heat.py @@ -23,6 +23,5 @@ from openstack_operator.tests.unit import base class HeatAPIDeploymentTestCase(base.DeploymentTestCase): """Basic tests for the Deployment.""" - SAMPLE_FILE = 'orchestration_v1alpha1_heat.yaml' + RELEASE_TYPE = 'heat' TEMPLATE_FILE = 'heat/deployment.yml.j2' - NAMESPACE_CHECK = False diff --git a/openstack_operator/tests/unit/test_horizon.py b/openstack_operator/tests/unit/test_horizon.py index e598b0a9..ba853f19 100644 --- a/openstack_operator/tests/unit/test_horizon.py +++ b/openstack_operator/tests/unit/test_horizon.py @@ -23,6 +23,5 @@ from openstack_operator.tests.unit import base class HorizonDeploymentTestCase(base.DeploymentTestCase): """Basic tests for the Deployment.""" - SAMPLE_FILE = 'dashboard_v1alpha1_horizon.yaml' + RELEASE_TYPE = 'horizon' TEMPLATE_FILE = 'horizon/deployment.yml.j2' - NAMESPACE_CHECK = False diff --git a/openstack_operator/tests/unit/test_keystone.py b/openstack_operator/tests/unit/test_keystone.py index 34c96cc9..c501fca1 100644 --- a/openstack_operator/tests/unit/test_keystone.py +++ b/openstack_operator/tests/unit/test_keystone.py @@ -23,6 +23,5 @@ from openstack_operator.tests.unit import base class KeystoneDeploymentTestCase(base.DeploymentTestCase): """Basic tests for the Deployment.""" - SAMPLE_FILE = 'identity_v1alpha1_keystone.yaml' + RELEASE_TYPE = 'keystone' TEMPLATE_FILE = 'keystone/deployment.yml.j2' - NAMESPACE_CHECK = False diff --git a/openstack_operator/tests/unit/test_mcrouter.py b/openstack_operator/tests/unit/test_mcrouter.py index 5223a5a4..97e213e2 100644 --- a/openstack_operator/tests/unit/test_mcrouter.py +++ b/openstack_operator/tests/unit/test_mcrouter.py @@ -25,3 +25,4 @@ class McrouterDeploymentTestCase(base.StatefulSetTestCase): SAMPLE_FILE = 'infrastructure_v1alpha1_mcrouter.yaml' TEMPLATE_FILE = 'mcrouter/deployment.yml.j2' + AUTO_GENERATED = False diff --git a/openstack_operator/tests/unit/test_memcached.py b/openstack_operator/tests/unit/test_memcached.py index 5ff96c12..a0ad3550 100644 --- a/openstack_operator/tests/unit/test_memcached.py +++ b/openstack_operator/tests/unit/test_memcached.py @@ -43,3 +43,4 @@ class MemcachedStatefulSetTestCase(base.StatefulSetTestCase): SAMPLE_FILE = 'infrastructure_v1alpha1_memcached.yaml' TEMPLATE_FILE = 'memcached/statefulset.yml.j2' + AUTO_GENERATED = False