def update(res_type, obj):
     if not obj.uuid:
         obj.uuid = VncApiMock.name_to_id(res_type, obj.name)
     if obj.uuid is None:
         raise NoIdError("Object does not exist.")
     if obj.uuid not in DBMock.get_dict(res_type.replace('-', '_')):
         raise NoIdError("Object does not exist.")
     DBMock.update(res_type.replace('-', '_'), obj.uuid, VncApiMock.object_to_dict(obj))
 def read(res_type, fq_name=None, fq_name_str=None, id=None, fields=None):
     (args_ok, result) = VncApiMock._read_args_to_id(res_type, fq_name, fq_name_str, id)
     if not args_ok:
         return result
     id = result
     if id is None:
         raise NoIdError("Object does not exist.")
     ok, ret = DBMock.read(res_type.replace('-', '_'), [id])
     if (not ok) or (len(ret) < 1):
         raise NoIdError("Object does not exist.")
     return VncApiMock.object_from_dict(res_type, ret[0])
Beispiel #3
0
    def test_create_pool(self):
        tenant_id = _uuid()
        pool_id = _uuid()
        vip_id = _uuid()
        subnet_id = _uuid()

        api = self.api_server

        project = Project(name='test')
        project.uuid = tenant_id
        template = ServiceTemplate('lb-test', project)
        template.uuid = _uuid()

        pool_attrs = LoadbalancerPoolType()
        pool_attrs.subnet_id = subnet_id
        pool = LoadbalancerPool(
            pool_id, project, loadbalancer_pool_properties=pool_attrs)
        pool.uuid = pool_id

        vip_attrs = VirtualIpType()
        vip_attrs.subnet_id = subnet_id
        vip_attrs.address = '127.0.0.1'
        vip = VirtualIp(vip_id, project, virtual_ip_properties=vip_attrs)
        vip.uuid = vip_id
        vip.set_loadbalancer_pool(pool)

        vnet = VirtualNetwork('test', project)
        vnet.uuid = _uuid()

        vmi = VirtualMachineInterface(vip_id, project)
        vmi.uuid = _uuid()
        vmi.set_virtual_network(vnet)
        iip = InstanceIp(vip_id, instance_ip_address='127.0.0.1')
        iip.uuid = _uuid()
        iip.set_virtual_machine_interface(vmi)

        iip_refs = [
            {'to': iip.get_fq_name(), 'uuid': iip.uuid}
        ]
        vmi.get_instance_ip_back_refs = mock.Mock()
        vmi.get_instance_ip_back_refs.return_value = iip_refs

        vip.set_virtual_machine_interface(vmi)

        api.virtual_service_template_read = template
        api.loadbalancer_pool_read.return_value = pool
        api.virtual_ip_read.return_value = vip
        api.kv_retrieve.return_value = '%s %s' % (vnet.uuid, subnet_id)
        api.virtual_machine_interface_read.return_value = vmi
        api.instance_ip_read.return_value = iip
        api.service_instance_read.side_effect = NoIdError('404')

        context = {}
        pool_data = {
            'id': pool_id,
            'vip_id': vip_id
        }
        self.driver.create_pool(context, pool_data)
        api.service_instance_create.assert_called_with(mock.ANY)
def test_read_no_project(vnc_api_client, vnc_lib):
    vnc_lib.project_read.side_effect = NoIdError(0)

    project = vnc_api_client.read_or_create_project()

    vnc_lib.project_create.assert_called_once()
    assert project.name == VNC_VCENTER_PROJECT
    assert project.fq_name == [VNC_ROOT_DOMAIN, VNC_VCENTER_PROJECT]
def test_read_no_ipam(vnc_api_client, vnc_lib, project):
    vnc_lib.network_ipam_read.side_effect = NoIdError(0)
    vnc_lib.project_read.return_value = project

    ipam = vnc_api_client.read_or_create_ipam()

    vnc_lib.network_ipam_create.assert_called_once()
    assert ipam.name == VNC_VCENTER_IPAM
    assert ipam.fq_name == ['domain-name', 'project-name', VNC_VCENTER_IPAM]
 def delete(res_type, fq_name=None, id=None, ifmap_id=None):
     (args_ok, result) = VncApiMock._read_args_to_id(res_type, fq_name=fq_name, id=id)
     if not args_ok:
         return result
     id = result
     if id is None:
         raise NoIdError("Object does not exist.")
     obj = DBMock.read(res_type.replace('-', '_'), [id])
     VncApiMock.name_to_uuid.pop(obj.get_name())
     DBMock.delete(res_type.replace('-', '_'), id)
def test_read_no_security_group(vnc_api_client, vnc_lib, project):
    vnc_lib.security_group_read.side_effect = NoIdError(0)
    vnc_lib.project_read.return_value = project

    security_group = vnc_api_client.read_or_create_security_group()

    vnc_lib.security_group_create.assert_called_once()
    assert VNC_VCENTER_DEFAULT_SG == security_group.name
    assert security_group.fq_name == [
        'domain-name', 'project-name', VNC_VCENTER_DEFAULT_SG
    ]
Beispiel #8
0
 def get_resource(self, context, id, fields=None):
     """ Implement GET by uuid.
     """
     tenant_id = str(uuid.UUID(context.tenant_id))
     try:
         obj = self.resource_read(id=id)
         project_id = self._get_object_tenant_id(obj)
         if not context.is_admin and tenant_id != project_id:
             raise NoIdError(id)
         res = self.make_dict(obj, fields)
     except NoIdError:
         raise self.get_exception_notfound(id=id)
     return res