Ejemplo n.º 1
0
                        ports = self.api.list_ports(kind='host')
                        expect(ports).to(be_empty)

                with description('invalid kind,'):
                    with it('returns no ports'):
                        ports = self.api.list_ports(kind='foo')
                        expect(ports).to(be_empty)

                with description('missing kind,'):
                    with it('returns no ports'):
                        ports = self.api.list_ports(kind='')
                        expect(ports).to(be_empty)

            with description('unsupported method,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api('/ports', 'PUT')).to(raise_api_exception(
                        405, headers={'Allow': "GET, POST"}))

        with description('get,'):
            with description('known existing port,'):
                with it('succeeds'):
                    expect(self.api.get_port('0')).to(be_valid_port)

            with description('non-existent port,'):
                with it('returns 404'):
                    expect(lambda: self.api.get_port('foo')).to(raise_api_exception(404))

            with description('invalid id,'):
                with it('returns 404'):
                    expect(lambda: self.api.get_port('Inv_port')).to(raise_api_exception(404))

            with description('unsupported method,'):
Ejemplo n.º 2
0
with description('Block,', 'block') as self:
    with description('REST API,'):
        with before.all:
            service = Service(CONFIG.service())
            self.process = service.start()
            self.api = client.api.BlockGeneratorApi(service.client())
            if not check_modules_exists(service.client(), 'block'):
                self.skip()

        with description('invalid HTTP methods,'):
            with description('/block-devices,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api(
                        '/block-devices', 'PUT')).to(
                            raise_api_exception(405, headers={'Allow': "GET"}))

            with description('/block-files,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api(
                        '/block-files', 'PUT')).to(
                            raise_api_exception(405,
                                                headers={'Allow':
                                                         "GET, POST"}))

            with description('/block-generators,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api(
                        '/block-generators', 'PUT')).to(
                            raise_api_exception(405,
                                                headers={'Allow':
Ejemplo n.º 3
0
        self.process = service.start()
        self.api = client.api.ModulesApi(service.client())

    with description('list, '):
        with description('all, '):
            with it('returns list of modules'):
                modules = self.api.list_modules()
                expect(modules).not_to(be_empty)
                for module in modules:
                    expect(module).to(be_valid_module)

            with description('unsupported method, '):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api(
                        '/modules', 'PUT')).to(
                            raise_api_exception(405, headers={'Allow': "GET"}))

    with description('get, '):
        with description('known module, '):
            with description('packetio'):
                with it('succeeds'):
                    module = self.api.get_module('packetio')
                    expect(module).to(be_valid_module)
                    expect(module.id).to(equal('packetio'))
                    expect(module.version.version).to(equal(1))

        with description('non-existent module, '):
            with it('returns 404'):
                expect(lambda: self.api.get_module(
                    'insertnotfoundmodulenamehere')).to(
                        raise_api_exception(404))
Ejemplo n.º 4
0
    return s


with description('Timesync,', 'timesync') as self:
    with before.all:
        service = Service(CONFIG.service())
        self.process = service.start()
        self.api = client.api.TimeSyncApi(service.client())

    with description('counters,'):
        with description('unsupported method,'):
            with it('returns 405'):
                expect(lambda: self.api.api_client.call_api(
                    '/time-counters', 'PUT')).to(
                        raise_api_exception(405, headers={'Allow': "GET"}))

        with description('GET,'):
            with description('list,'):
                with it('succeeds'):
                    counters = self.api.list_time_counters()
                    expect(counters).not_to(be_empty)
                    for counter in counters:
                        expect(counter).to(be_valid_counter)

            with description('valid counter,'):
                with it('succeeds'):
                    for counter in self.api.list_time_counters():
                        expect(self.api.get_time_counter(
                            counter.id)).to(be_valid_counter)
Ejemplo n.º 5
0
with description('Packet Generator,', 'packet_generator') as self:
    with description('REST API'):

        with before.all:
            service = Service(CONFIG.service())
            self.process = service.start()
            self.api = client.api.PacketGeneratorsApi(service.client())
            if not check_modules_exists(service.client(), 'packet-generator'):
                self.skip()

        with description('invalid HTTP methods,'):
            with description('/packet/generators,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api(
                        '/packet/generators', 'PUT')).to(
                            raise_api_exception(
                                405, headers={'Allow': "DELETE, GET, POST"}))

            with description('/packet/generator-results,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api(
                        '/packet/generator-results', 'PUT')).to(
                            raise_api_exception(
                                405, headers={'Allow': "DELETE, GET"}))

            with description('/packet/tx-flows,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api(
                        '/packet/tx-flows', 'PUT')).to(
                            raise_api_exception(405, headers={'Allow': "GET"}))

        with description('list generators,'):
Ejemplo n.º 6
0
                        intfs = self.api.list_interfaces(ipv6_address='')
                        expect(intfs).to(be_empty)

        with description('get,'):
            with description('IPv4,'):
                with description('known existing interface,'):
                    with before.each:
                        intf = self.api.create_interface(example_ipv4_interface(self.api.api_client))
                        expect(intf).to(be_valid_interface)
                        self.intf, self.cleanup = intf, intf

                    with it('succeeds'):
                        expect(self.api.get_interface(self.intf.id)).to(be_valid_interface)

                    with it('returns 405'):
                        expect(lambda: self.api.api_client.call_api('/interfaces', 'PUT')).to(raise_api_exception(405, headers={'Allow': "GET, POST"}))
    
            with description('IPv6,'):
                with description('known existing interface,'):
                    with before.each:
                        intf = self.api.create_interface(example_ipv6_interface(self.api.api_client))
                        expect(intf).to(be_valid_interface)
                        self.intf, self.cleanup = intf, intf

                    with it('succeeds'):
                        expect(self.api.get_interface(self.intf.id)).to(be_valid_interface)

                    with it('returns 405'):
                        expect(lambda: self.api.api_client.call_api('/interfaces', 'PUT')).to(raise_api_exception(405, headers={'Allow': "GET, POST"}))

            with description('non-existent interface,'):
Ejemplo n.º 7
0
            for gen in self._api.list_cpu_generators():
                if gen.running:
                    self._api.stop_cpu_generator(gen.id)
                self._api.delete_cpu_generator(gen.id)

            self._process.terminate()
            self._process.wait()
        except AttributeError:
            pass

    with description('Information'):
        with description('/cpu-info'):
            with context('PUT'):
                with it('not allowed (405)'):
                    expect(lambda: self._api.api_client.call_api('/cpu-info', 'PUT')).to(
                        raise_api_exception(405, headers={'Allow': "GET"}))

            with context('GET'):
                with before.all:
                    self._result = self._api.get_cpu_info_with_http_info(
                        _return_http_data_only=False)

                with it('success (200)'):
                    expect(self._result[1]).to(equal(200))

                with it('has Content-Type: application/json header'):
                    expect(self._result[2]).to(has_json_content_type)

                with it('valid cpu info'):
                    expect(self._result[0]).to(be_valid_cpu_info)
Ejemplo n.º 8
0
                        self._result = self._api.get_cpu_generator_with_http_info(
                            self._g7r.id, _return_http_data_only=False)

                    with it('succeeded'):
                        expect(self._result[1]).to(equal(200))

                    with it('has Content-Type: application/json header'):
                        expect(self._result[2]).to(has_json_content_type)

                    with it('generator object'):
                        expect(self._result[0]).to(be_valid_cpu_generator)

                with description('by non-existent ID'):
                    with it('not found (404)'):
                        expr = lambda: self._api.get_cpu_generator('unknown')
                        expect(expr).to(raise_api_exception(404))

                with description('by invalid ID'):
                    with it('bad request (400)'):
                        expr = lambda: self._api.get_cpu_generator('bad_id')
                        expect(expr).to(raise_api_exception(400))

            with context('DELETE'):
                with description('by existing ID'):
                    with it('removed'):
                        result = self._api.delete_cpu_generator_with_http_info(
                            self._g7r.id, _return_http_data_only=False)
                        expect(result[1]).to(equal(204))

                    with it('not found'):
                        expr = lambda: self._api.get_cpu_generator(self._g7r.id)
Ejemplo n.º 9
0
    return [gen1, gen2]


with description('Packet Generator,', 'packet_generator') as self:
    with description('REST API'):

        with before.all:
            service = Service(CONFIG.service())
            self.process = service.start()
            self.api = client.api.PacketGeneratorsApi(service.client())

        with description('invalid HTTP methods,'):
            with description('/packet/generators,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api('/packet/generators', 'PUT')).to(
                        raise_api_exception(405, headers={'Allow': "DELETE, GET, POST"}))

            with description('/packet/generator-results,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api('/packet/generator-results', 'PUT')).to(
                        raise_api_exception(405, headers={'Allow': "DELETE, GET"}))

            with description('/packet/tx-flows,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api('/packet/tx-flows', 'PUT')).to(
                        raise_api_exception(405, headers={'Allow': "GET"}))

        with description('list generators,'):
            with before.each:
                gen = self.api.create_packet_generator(generator_model(self.api.api_client))
                expect(gen).to(be_valid_packet_generator)
Ejemplo n.º 10
0
    return s


with description('Timesync,', 'timesync') as self:
    with before.all:
        service = Service(CONFIG.service())
        self.process = service.start()
        self.api = client.api.TimeSyncApi(service.client())

    with description('counters,'):
        with description('unsupported method,'):
            with it('returns 405'):
                expect(lambda: self.api.api_client.call_api(
                    '/time-counters', 'PUT')).to(
                        raise_api_exception(405, headers={'Allow': "GET"}))

        with description('GET,'):
            with description('list,'):
                with it('succeeds'):
                    counters = self.api.list_time_counters()
                    expect(counters).not_to(be_empty)
                    for counter in counters:
                        expect(counter).to(be_valid_counter)

            with description('valid counter,'):
                with it('succeeds'):
                    for counter in self.api.list_time_counters():
                        expect(self.api.get_time_counter(counter.id)).to(be_valid_counter)

            with description('non-existent counter,'):
Ejemplo n.º 11
0
            with description('IPv4,'):
                with description('known existing interface,'):
                    with before.each:
                        intf = self.api.create_interface(
                            example_ipv4_interface(self.api.api_client))
                        expect(intf).to(be_valid_interface)
                        self.intf, self.cleanup = intf, intf

                    with it('succeeds'):
                        expect(self.api.get_interface(
                            self.intf.id)).to(be_valid_interface)

                    with it('returns 405'):
                        expect(lambda: self.api.api_client.call_api(
                            '/interfaces', 'PUT')).to(
                                raise_api_exception(
                                    405, headers={'Allow': "GET, POST"}))

            with description('IPv6,'):
                with description('known existing interface,'):
                    with before.each:
                        intf = self.api.create_interface(
                            example_ipv6_interface(self.api.api_client))
                        expect(intf).to(be_valid_interface)
                        self.intf, self.cleanup = intf, intf

                    with it('succeeds'):
                        expect(self.api.get_interface(
                            self.intf.id)).to(be_valid_interface)

                    with it('returns 405'):
                        expect(lambda: self.api.api_client.call_api(
Ejemplo n.º 12
0
                            self._g7r.id, _return_http_data_only=False)

                    with it('succeeded'):
                        expect(self._result[1]).to(equal(200))

                    with it('has Content-Type: application/json header'):
                        expect(self._result[2]).to(has_json_content_type)

                    with it('generator object'):
                        expect(self._result[0]).to(be_valid_memory_generator)

                with description('by non-existent ID'):
                    with it('not found (404)'):
                        expr = lambda: self._api.get_memory_generator('unknown'
                                                                      )
                        expect(expr).to(raise_api_exception(404))

                with description('by invalid ID'):
                    with it('bad request (400)'):
                        expr = lambda: self._api.get_memory_generator('bad_id')
                        expect(expr).to(raise_api_exception(400))

            with context('DELETE'):
                with description('by existing ID'):
                    with it('removed'):
                        result = self._api.delete_memory_generator_with_http_info(
                            self._g7r.id, _return_http_data_only=False)
                        expect(result[1]).to(equal(204))

                    with it('not found'):
                        expr = lambda: self._api.get_memory_generator(self._g7r
Ejemplo n.º 13
0
            self.intf_api = client.api.InterfacesApi(self.api.api_client)
            if not check_modules_exists(service.client(), 'packetio', 'packet-capture'):
                self.skip()

            # By default, ping is a privileged process.  We need it unprivileged
            # to use LD_PRELOAD, so just make a copy as a regular user.
            self.temp_dir = tempfile.mkdtemp()
            shutil.copy(PING, self.temp_dir)
            self.temp_ping = os.path.join(self.temp_dir, os.path.basename(PING))
            expect(os.path.isfile(self.temp_ping))

        with description('invalid HTTP methods,'):
            with description('/packet/captures,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api('/packet/captures', 'PUT')).to(
                        raise_api_exception(405, headers={'Allow': "DELETE, GET, POST"}))

            with description('/packet/capture-results,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api('/packet/capture-results', 'PUT')).to(
                        raise_api_exception(405, headers={'Allow': "DELETE, GET"}))

        with description('list captures,'):
            with before.each:
                cap = self.api.create_packet_capture(capture_model(self.api.api_client))
                expect(cap).to(be_valid_packet_capture)
                self.capture = cap

            with description('unfiltered,'):
                with it('succeeds'):
                    captures = self.api.list_packet_captures()
Ejemplo n.º 14
0
                with description('invalid kind,'):
                    with it('returns no ports'):
                        ports = self.api.list_ports(kind='foo')
                        expect(ports).to(be_empty)

                with description('missing kind,'):
                    with it('returns no ports'):
                        ports = self.api.list_ports(kind='')
                        expect(ports).to(be_empty)

            with description('unsupported method,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api(
                        '/ports', 'PUT')).to(
                            raise_api_exception(405,
                                                headers={'Allow':
                                                         "GET, POST"}))

        with description('get,'):
            with description('known existing port,'):
                with it('succeeds'):
                    expect(self.api.get_port('0')).to(be_valid_port)

            with description('non-existent port,'):
                with it('returns 404'):
                    expect(lambda: self.api.get_port('foo')).to(
                        raise_api_exception(404))

            with description('invalid id,'):
                with it('returns 404'):
                    expect(lambda: self.api.get_port('Inv_port')).to(