import os import client.api import client.models from common import Config, Service from common.matcher import be_valid_port, raise_api_exception CONFIG = Config(os.path.join(os.path.dirname(__file__), os.environ.get('MAMBA_CONFIG', 'config.yaml'))) with description('Ports,', 'ports') as self: with description('REST API,'): with before.all: service = Service(CONFIG.service()) self.process = service.start() self.api = client.api.PortsApi(service.client()) with description('list,'): with description('unfiltered,'): with it('returns valid ports'): ports = self.api.list_ports() expect(ports).not_to(be_empty) for port in ports: expect(port).to(be_valid_port) with description('filtered,'): with description('known existing kind,'): with it('returns valid ports of that kind'): ports = self.api.list_ports(kind='dpdk')
shim = Service(CONFIG.shim()) dst_ip = get_interface_address(api_client, dst_id, domain) with open(os.devnull, 'w') as null: p = subprocess.Popen(ping_command(ping_binary, dst_ip, domain), stdout=null, stderr=null, env={'LD_PRELOAD': shim.config.path, 'OP_BINDTODEVICE': src_id}) p.wait() expect(p.returncode).to(equal(0)) with description('Dataplane,', 'dataplane') as self: with before.all: service = Service(CONFIG.service('dataplane')) self.process = service.start() self.api = client.api.InterfacesApi(service.client()) if not check_modules_exists(service.client(), 'packetio'): self.skip() with description('ipv4,', 'dataplane:ipv4'): with description('ping,', 'dataplane:ipv4:ping'): with before.all: # 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))
from mamba import description, before, after, it from expects import expect import os import client.api from common import Config, Service from common.helper import check_modules_exists CONFIG = Config( os.path.join(os.path.dirname(__file__), os.environ.get('MAMBA_CONFIG', 'config.yaml'))) with description('PacketIO arguments,', 'packetio_args'): with description('Empty core mask,'): with before.all: service = Service(CONFIG.service('packetio-args-1')) self.process = service.start() self.api = client.api.PortsApi(service.client()) if not check_modules_exists(service.client(), 'packetio'): self.skip() with description('binary started,'): with it('has no port handlers'): expect( lambda: self.api.list_ports().to(raise_api_exception(405))) with after.all: try: self.process.terminate() self.process.wait() except AttributeError:
from mamba import description, before, after, it from expects import * import os import client.api import client.models from common import Config, Service from common.matcher import be_valid_module, raise_api_exception CONFIG = Config( os.path.join(os.path.dirname(__file__), os.environ.get('MAMBA_CONFIG', 'config.yaml'))) with description('Modules, ', 'modules') as self: with before.all: service = Service(CONFIG.service()) 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(
time.sleep(initial_sleep) while True: result = gen_client.get_packet_generator_result(result_id) expect(result).to(be_valid_packet_generator_result) if result.flow_counters.packets_actual > 0 and not result.active: break time.sleep(POLL_INTERVAL) with description('Packet Generator Drop Mode,', 'packet_generator_drop') as self: with description('Drops and Stops'): with before.all: service = Service(CONFIG.service('packet-generator-drop')) self.process = service.start() self.api = client.api.PacketGeneratorsApi(service.client()) if not check_modules_exists(service.client(), 'packet-generator'): self.skip() with description('overload transmit path,'): with it('stops on-time and drops packets'): time = client.models.TrafficDurationTime() time.value = 100 time.units = "milliseconds" duration = client.models.TrafficDuration() duration.time = time gen = packet_generator_model(self.api.api_client) gen.config.duration = duration