Example #1
0
    def test_create(self):
        ep_def = policy.EnforcementPointDef('ep1',
                                            name='The Point',
                                            ip_address='1.1.1.1',
                                            username='******',
                                            password='******')

        self.policy_api.create_or_update(ep_def)
        ep_path = policy.EnforcementPointDef('ep1').get_resource_path()
        self.assert_json_call('PATCH',
                              self.client,
                              ep_path,
                              data=ep_def.get_obj_dict())
Example #2
0
 def test_get(self):
     id = '111'
     with mock.patch.object(self.policy_api, "get") as api_call:
         self.resourceApi.get(id, tenant=TEST_TENANT)
         expected_def = policy_defs.EnforcementPointDef(ep_id=id,
                                                        tenant=TEST_TENANT)
         self.assert_called_with_def(api_call, expected_def)
    def update(self, ep_id, name=None, description=None,
               ip_address=None, username=None,
               password=None, thumbprint=None,
               edge_cluster_id=None, transport_zone_id=None,
               tenant=policy_constants.POLICY_INFRA_TENANT):
        """Update the enforcement point.

        username & password must be defined
        """
        if not username or password is None:
            # username/password must be provided
            err_msg = (_("Cannot update an enforcement point without "
                         "username and password"))
            raise exceptions.ManagerError(details=err_msg)
        # Get the original body because ip & thumbprint are mandatory
        body = self.get(ep_id)
        ep_def = policy_defs.EnforcementPointDef(ep_id=ep_id, tenant=tenant)
        ep_def.update_attributes_in_body(body=body,
                                         name=name,
                                         description=description,
                                         ip_address=ip_address,
                                         username=username,
                                         password=password,
                                         edge_cluster_id=edge_cluster_id,
                                         transport_zone_id=transport_zone_id,
                                         thumbprint=thumbprint)
        # update the backend
        return self.policy_api.create_or_update(ep_def)
Example #4
0
    def test_create(self):
        name = 'ep'
        description = 'desc'
        ip_address = '1.1.1.1'
        username = '******'
        password = '******'
        thumbprint = 'abc'
        edge_cluster_id = 'ec1'
        transport_zone_id = 'tz1'
        with mock.patch.object(self.policy_api,
                               "create_or_update") as api_call:
            self.resourceApi.create_or_overwrite(
                name,
                description=description,
                ip_address=ip_address,
                thumbprint=thumbprint,
                username=username,
                password=password,
                edge_cluster_id=edge_cluster_id,
                transport_zone_id=transport_zone_id,
                tenant=TEST_TENANT)

            expected_def = policy_defs.EnforcementPointDef(
                ep_id=mock.ANY,
                name=name,
                description=description,
                ip_address=ip_address,
                username=username,
                thumbprint=thumbprint,
                password=password,
                edge_cluster_id=edge_cluster_id,
                transport_zone_id=transport_zone_id,
                tenant=TEST_TENANT)
            self.assert_called_with_def(api_call, expected_def)
Example #5
0
 def test_get_by_name(self):
     name = 'ep1'
     with mock.patch.object(
             self.policy_api,
             "list",
             return_value={'results': [{
                 'display_name': name
             }]}) as api_call:
         obj = self.resourceApi.get_by_name(name, tenant=TEST_TENANT)
         self.assertIsNotNone(obj)
         expected_def = policy_defs.EnforcementPointDef(tenant=TEST_TENANT)
         self.assert_called_with_def(api_call, expected_def)
Example #6
0
    def test_create(self):
        map_def = policy.DeploymentMapDef('dm1', domain_id='d1', ep_id='ep1')

        self.policy_api.create_or_update(map_def)
        ep_path = policy.EnforcementPointDef('ep1').get_resource_full_path()
        expected_data = {
            'id': 'dm1',
            'display_name': None,
            'description': None,
            'enforcement_point_path': ep_path
        }

        self.assert_json_call('PATCH',
                              self.client,
                              'infra/domains/d1/domain-deployment-maps/dm1',
                              data=expected_data)
Example #7
0
 def test_update(self):
     id = '111'
     name = 'new name'
     username = '******'
     password = '******'
     ip_address = '1.1.1.1'
     thumbprint = 'abc'
     edge_cluster_id = 'ec1'
     transport_zone_id = 'tz1'
     with mock.patch.object(self.policy_api,
                            "create_or_update") as update_call,\
         mock.patch.object(self.policy_api, "get", return_value={'id': id}):
         self.resourceApi.update(id,
                                 name=name,
                                 username=username,
                                 password=password,
                                 ip_address=ip_address,
                                 thumbprint=thumbprint,
                                 edge_cluster_id=edge_cluster_id,
                                 transport_zone_id=transport_zone_id,
                                 tenant=TEST_TENANT)
         expected_def = policy_defs.EnforcementPointDef(ep_id=id,
                                                        tenant=TEST_TENANT)
         expected_dict = {
             'id': id,
             'display_name': name,
             'resource_type': 'EnforcementPoint',
             'connection_info': {
                 'username': username,
                 'password': password,
                 'thumbprint': thumbprint,
                 'enforcement_point_address': ip_address,
                 'edge_cluster_ids': [edge_cluster_id],
                 'transport_zone_ids': [transport_zone_id],
                 'resource_type': 'NSXTConnectionInfo'
             }
         }
         self.assert_called_with_def_and_dict(update_call, expected_def,
                                              expected_dict)
 def create_or_overwrite(self, name, ep_id=None, description=None,
                         ip_address=None, username=None,
                         password=None, thumbprint=None,
                         edge_cluster_id=None, transport_zone_id=None,
                         tenant=policy_constants.POLICY_INFRA_TENANT):
     if not ip_address or not username or password is None:
         err_msg = (_("Cannot create an enforcement point without "
                      "ip_address, username and password"))
         raise exceptions.ManagerError(details=err_msg)
     ep_id = self._init_obj_uuid(ep_id)
     ep_def = policy_defs.EnforcementPointDef(
         ep_id=ep_id,
         name=name,
         description=description,
         ip_address=ip_address,
         username=username,
         password=password,
         thumbprint=thumbprint,
         edge_cluster_id=edge_cluster_id,
         transport_zone_id=transport_zone_id,
         tenant=tenant)
     return self.policy_api.create_or_update(ep_def)
Example #9
0
 def test_list(self):
     with mock.patch.object(self.policy_api, "list") as api_call:
         self.resourceApi.list(tenant=TEST_TENANT)
         expected_def = policy_defs.EnforcementPointDef(tenant=TEST_TENANT)
         self.assert_called_with_def(api_call, expected_def)
 def get_realized_state(self, ep_id,
                        tenant=policy_constants.POLICY_INFRA_TENANT):
     ep_def = policy_defs.EnforcementPointDef(ep_id=ep_id, tenant=tenant)
     path = ep_def.get_realized_state_path()
     return self._get_realized_state(path)
 def list(self, tenant=policy_constants.POLICY_INFRA_TENANT):
     ep_def = policy_defs.EnforcementPointDef(tenant=tenant)
     return self.policy_api.list(ep_def)['results']
 def get(self, ep_id,
         tenant=policy_constants.POLICY_INFRA_TENANT):
     ep_def = policy_defs.EnforcementPointDef(
         ep_id=ep_id, tenant=tenant)
     return self.policy_api.get(ep_def)
 def delete(self, ep_id,
            tenant=policy_constants.POLICY_INFRA_TENANT):
     ep_def = policy_defs.EnforcementPointDef(
         ep_id=ep_id, tenant=tenant)
     self.policy_api.delete(ep_def)