Example #1
0
    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))

            with description('client interface,'):
                with it('succeeds'):
                    do_ping(self.api, self.temp_ping,
Example #2
0
from common.matcher import (be_valid_block_device, be_valid_block_file,
                            be_valid_block_generator,
                            be_valid_block_generator_result, has_location,
                            raise_api_exception, be_valid_dynamic_results)

CONFIG = Config(
    os.path.join(os.path.dirname(__file__),
                 os.environ.get('MAMBA_CONFIG', 'config.yaml')))

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':
Example #3
0
    gen1 = generator_model(api_client)
    gen1.target_id = ports[0].id
    gen2 = generator_model(api_client)
    gen2.target_id = ports[1].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())
            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(
Example #4
0
def analyzer_models(api_client, protocol_counters=None, flow_counters=None):
    ana1 = analyzer_model(api_client, protocol_counters, flow_counters)
    ana2 = analyzer_model(api_client, protocol_counters, flow_counters)
    ana2.source_id = get_second_port_id(api_client)
    return [ana1, ana2]


with description('Packet Analyzer,', 'packet_analyzer') as self:
    with description('REST API,'):

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

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

            with description('/packet/analyzer-results,'):
                with it('returns 405'):
                    expect(lambda: self.api.api_client.call_api(
                        '/packet/analyzer-results', 'PUT')).to(
                            raise_api_exception(
Example #5
0

CONFIG = Config(os.path.join(os.path.dirname(__file__),
                os.environ.get('MAMBA_CONFIG', 'config.yaml')))


def approximately_equal(a, b):
    return abs(a - b) < 0.01


with description('CPU Generator Module', 'cpu') as self:
    with before.all:
        service = Service(CONFIG.service())
        self._process = service.start()
        self._api = client.api.CpuGeneratorApi(service.client())
        if not check_modules_exists(service.client(), 'cpu'):
            self.skip()

    with after.all:
        try:
            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'):
Example #6
0
from common.matcher import (has_location, has_json_content_type,
                            raise_api_exception, be_valid_memory_info,
                            be_valid_memory_generator,
                            be_valid_memory_generator_result,
                            be_valid_dynamic_results)

CONFIG = Config(
    os.path.join(os.path.dirname(__file__),
                 os.environ.get('MAMBA_CONFIG', 'config.yaml')))

with description('Memory Generator Module', 'memory') as self:
    with before.all:
        service = Service(CONFIG.service())
        self._process = service.start()
        self._api = client.api.MemoryGeneratorApi(service.client())
        if not check_modules_exists(service.client(), 'memory'):
            self.skip()

    with after.all:
        try:
            for gen in self.api.list_memory_generators():
                if gen.running:
                    self.api.stop_memory_generator(gen.id)
                self.api.delete_memory_generator(gen.id)
        except AttributeError:
            pass

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