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,'):
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':
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))
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('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,'):
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,'):
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)
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)
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)
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,'):
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(
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
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()
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(