def test_namespace_is_isolated(self):
        annotations = {'opencontrail.org/isolation': "true"}

        # Add first namespace
        ns1_name = "isolated_ns1"
        ns1_uuid = str(uuid.uuid4())
        ns1_add_event = self.create_add_namespace_event(ns1_name, ns1_uuid)
        ns1_add_event['object']['metadata']['annotations'] = annotations
        NamespaceKM.locate(ns1_uuid, ns1_add_event['object'])
        self.enqueue_event(ns1_add_event)
        time.sleep(2)

        # Add second namespace
        ns2_name = 'isolated_ns2'
        ns2_uuid = str(uuid.uuid4())
        ns2_add_event = self.create_add_namespace_event(ns2_name, ns2_uuid)
        ns2_add_event['object']['metadata']['annotations'] = annotations
        NamespaceKM.locate(ns2_uuid, ns2_add_event['object'])
        self.enqueue_event(ns2_add_event)
        time.sleep(2)

        fqname = ['default-domain', ns1_name, ns1_name + '-vn']
        vn = self._vnc_lib.virtual_network_read(fq_name=fqname)
        self.assertIsNotNone(vn)
        self.assertEquals(ns1_name + '-vn', vn.name)

        fqname = ['default-domain', ns2_name, ns2_name + '-vn']
        vn = self._vnc_lib.virtual_network_read(fq_name=fqname)
        self.assertIsNotNone(vn)
        self.assertEquals(ns2_name + '-vn', vn.name)
    def test_add_namespace_with_custom_network_annotation(self):
        kube_config.VncKubernetesConfig.args().cluster_project = None
        # Create network for Pod
        proj_fq_name = ['default-domain', 'default']
        proj_obj = self._vnc_lib.project_read(fq_name=proj_fq_name)
        self.create_network('network1', proj_obj)
        # Add first namespace
        eval_vn_dict = \
            '{"domain":"default-domain","project":"default","name":"network1"}'
        ns1_name = 'namespace1'
        ns1_uuid = str(uuid.uuid4())
        ns1_add_event = self.create_add_namespace_event(ns1_name, ns1_uuid)
        ns1_annotations = {
            'opencontrail.org/network': eval_vn_dict
        }
        ns1_add_event['object']['metadata']['annotations'] = ns1_annotations
        NamespaceKM.locate(ns1_uuid, ns1_add_event['object'])
        self.enqueue_event(ns1_add_event)
        self.wait_for_all_tasks_done()

        proj = self._vnc_lib.project_read(fq_name=["default-domain", ns1_name])
        self.assertIsNotNone(proj)
        self.assertEquals(ns1_name, proj.name)

        fqname = ['default-domain', 'default', 'network1']
        vn = self._vnc_lib.virtual_network_read(fq_name=fqname)
        self.assertIsNotNone(vn)
        self.assertEquals('network1', vn.name)
Beispiel #3
0
 def _create_and_add_namespace(self, name, spec, annotations, locate=False):
     ns_uuid = str(uuid.uuid4())
     ns_meta = {'name': name, 'uid': ns_uuid}
     if annotations:
         ns_meta['annotations'] = annotations
     ns_add_event = self.create_event('Namespace', spec, ns_meta, 'ADDED')
     if locate:
         NamespaceKM.locate(name, ns_add_event['object'])
     self.enqueue_event(ns_add_event)
     self.wait_for_all_tasks_done()
     return ns_uuid
 def _create_and_add_namespace(self, name, spec, annotations,
                               locate=False):
     ns_uuid = str(uuid.uuid4())
     ns_meta = {'name': name,
                'uid': ns_uuid}
     if annotations:
         ns_meta['annotations'] = annotations
     ns_add_event = self.create_event('Namespace', spec, ns_meta, 'ADDED')
     if locate:
         NamespaceKM.locate(name, ns_add_event['object'])
     self.enqueue_event(ns_add_event)
     self.wait_for_all_tasks_done()
     return ns_uuid
Beispiel #5
0
    def _mod_namespace(self, uuid, name, spec, annotations,
                            labels=None, locate=False):
        ns_uuid = uuid
        ns_meta = {'name': name,
                   'uid': ns_uuid}
        if annotations:
            ns_meta['annotations'] = annotations
        if labels:
            ns_meta['labels'] = labels

        ns_mod_event = self.create_event('Namespace', spec, ns_meta, 'MODIFIED')
        if locate:
            NamespaceKM.locate(name, ns_mod_event['object'])
        self.enqueue_event(ns_mod_event)
        self.wait_for_all_tasks_done()
    def _mod_namespace(self, uuid, name, spec, annotations,
                            labels=None, locate=False):
        ns_uuid = uuid
        ns_meta = {'name': name,
                   'uid': ns_uuid}
        if annotations:
            ns_meta['annotations'] = annotations
        if labels:
            ns_meta['labels'] = labels

        ns_mod_event = self.create_event('Namespace', spec, ns_meta, 'MODIFIED')
        if locate:
            NamespaceKM.locate(name, ns_mod_event['object'])
        self.enqueue_event(ns_mod_event)
        self.wait_for_all_tasks_done()
Beispiel #7
0
    def _create_namespace(self,
                          ns_name,
                          ns_eval_vn_dict,
                          is_isolated=False,
                          labels={}):
        ns_uuid = str(uuid.uuid4())
        ns_add_event = self.create_add_namespace_event(ns_name, ns_uuid)
        ns_object = ns_add_event['object']
        ns_object['spec'] = {}
        ns_meta = ns_object['metadata']
        ns_meta['annotations'] = {}

        ns_meta['name'] = ns_name
        ns_meta['uid'] = ns_uuid
        ns_meta['namespace'] = ns_name
        ns_meta['labels'] = labels

        if ns_eval_vn_dict:
            ns_meta['annotations']['opencontrail.org/network'] = \
                ns_eval_vn_dict
        if is_isolated:
            ns_meta['annotations']['opencontrail.org/isolation'] = 'true'

        NamespaceKM.delete(ns_name)
        ns = NamespaceKM.locate(ns_name, ns_object)

        self.enqueue_event(ns_add_event)
        self.wait_for_all_tasks_done()

        return ns.uuid
    def _create_namespace(self, ns_name, ns_eval_vn_dict, is_isolated=False, labels={}):
        ns_uuid = str(uuid.uuid4())
        ns_add_event = self.create_add_namespace_event(ns_name, ns_uuid)
        ns_object = ns_add_event['object']
        ns_object['spec'] = {}
        ns_meta = ns_object['metadata']
        ns_meta['annotations'] = {}

        ns_meta['name'] = ns_name
        ns_meta['uid'] = ns_uuid
        ns_meta['namespace'] = ns_name
        ns_meta['labels'] = labels

        if ns_eval_vn_dict:
            ns_meta['annotations']['opencontrail.org/network'] = \
                ns_eval_vn_dict
        if is_isolated:
            ns_meta['annotations']['opencontrail.org/isolation'] = 'true'

        NamespaceKM.delete(ns_name)
        ns = NamespaceKM.locate(ns_name, ns_object)

        self.enqueue_event(ns_add_event)
        self.wait_for_all_tasks_done()

        return ns.uuid
    def test_add_namespace_with_isolation_annotation_true(self):
        kube_config.VncKubernetesConfig.args().cluster_project = None
        annotations = {
            'opencontrail.org/isolation': "true"
        }

        # Add first namespace
        ns1_name = "isolated_ns1"
        ns1_uuid = str(uuid.uuid4())
        ns1_add_event = self.create_add_namespace_event(ns1_name, ns1_uuid)
        ns1_add_event['object']['metadata']['annotations'] = annotations
        NamespaceKM.locate(ns1_uuid, ns1_add_event['object'])
        self.enqueue_event(ns1_add_event)
        self.wait_for_all_tasks_done()

        proj = self._vnc_lib.project_read(fq_name=["default-domain", ns1_name])
        self.assertIsNotNone(proj)
        self.assertEquals(ns1_name, proj.name)

        fqname = ['default-domain', ns1_name, ns1_name+'-vn']
        vn = self._vnc_lib.virtual_network_read(fq_name=fqname)
        self.assertIsNotNone(vn)
        self.assertEquals(ns1_name+'-vn', vn.name)
    def test_namespace_custom_network(self):
        # Create network for Pod
        proj_fq_name = ['default-domain', 'default']
        proj_obj = self._vnc_lib.project_read(fq_name=proj_fq_name)
        vn_obj = self.create_network('network1', proj_obj)
        # Add first namespace
        eval_vn_dict = '{"domain":"default-domain","project":"default","name":"network1"}'
        ns1_name = 'namespace1'
        ns1_uuid = str(uuid.uuid4())
        ns1_add_event = self.create_add_namespace_event(ns1_name, ns1_uuid)
        ns1_annotations = {'opencontrail.org/network': eval_vn_dict}
        ns1_add_event['object']['metadata']['annotations'] = ns1_annotations
        NamespaceKM.locate(ns1_uuid, ns1_add_event['object'])
        self.enqueue_event(ns1_add_event)
        time.sleep(2)

        # Add second namespace
        vn_obj = self.create_network('network2', proj_obj)
        eval_vn_dict = '{"domain":"default-domain","project":"default","name":"network2"}'
        ns2_name = 'isolated_ns2'
        ns2_uuid = str(uuid.uuid4())
        ns2_add_event = self.create_add_namespace_event(ns2_name, ns2_uuid)
        ns2_annotations = {'opencontrail.org/network': eval_vn_dict}
        ns2_add_event['object']['metadata']['annotations'] = ns2_annotations
        NamespaceKM.locate(ns2_uuid, ns2_add_event['object'])
        self.enqueue_event(ns2_add_event)
        time.sleep(2)

        fqname = ['default-domain', 'default', 'network1']
        vn = self._vnc_lib.virtual_network_read(fq_name=fqname)
        self.assertIsNotNone(vn)
        self.assertEquals('network1', vn.name)

        fqname = ['default-domain', 'default', 'network2']
        vn = self._vnc_lib.virtual_network_read(fq_name=fqname)
        self.assertIsNotNone(vn)
        self.assertEquals('network2', vn.name)