fuel-qa/fuelweb_test/helpers/eb_tables.py
Alexandr Kostrikov e317c2d6d2 doc: Added an initial Sphinx documentation
I have added a auto-generated documentation. It is done with
Sphinx library. Sphinx uses reStructuredText as its markup language
and docstrings as a source for automated documentation.

According to https://www.python.org/dev/peps/pep-0257/
I used a """ for quotes in docstrings and made
"""Docstring."""-looking one-liners and correct indentation
for multiple-liners.
Based on https://github.com/kennethreitz/requests
I moved Makefile, requirements.txt and conf.py to /doc folder.
Also I decided to make fuel-qa documentation
similar to https://docs.python.org/2/tutorial/index.html
with single table of contents.
I have added empty __init__.py files to be able to produce
documentation.
I have added sys_test.log to .gitigonre because it has
been generated at the documentation build.

To make it faster and non-conflicting I added some banal
class descriptions in order to get them in auto-generated documentation.
I decided not to fight with warnings and poor docstring descriptions
I added to make documentation less conflicting and for a faster review.
Docstring improvements and detailed code description are left for later.
For the same reasons I decied not to add docstrings to all methods.
At a places where I made poor docstrings I have added a
TODO documentation.

Change-Id: I7701a9a3429abbf62b13ec5a31972298c0be5201
Related-Bug: #1321682
2015-05-07 17:42:38 +03:00

85 lines
2.5 KiB
Python

# Copyright 2013 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import subprocess
from fuelweb_test import logwrap
class Ebtables(object):
"""Ebtables.""" # TODO documentation
def __init__(self, target_devs, vlans):
super(Ebtables, self).__init__()
self.target_devs = target_devs
self.vlans = vlans
@logwrap
def restore_vlans(self):
for vlan in self.vlans:
for target_dev in self.target_devs:
Ebtables.restore_vlan(target_dev, vlan)
@logwrap
def restore_first_vlan(self):
for target_dev in self.target_devs:
Ebtables.restore_vlan(target_dev, self.vlans[0])
@logwrap
def block_first_vlan(self):
for target_dev in self.target_devs:
Ebtables.block_vlan(target_dev, self.vlans[0])
@staticmethod
@logwrap
def block_mac(mac):
return subprocess.check_output(
['sudo', 'ebtables', '-t', 'filter', '-A', 'FORWARD', '-s',
mac, '-j', 'DROP'],
stderr=subprocess.STDOUT
)
@staticmethod
@logwrap
def restore_mac(mac):
return subprocess.call(
[
'sudo', 'ebtables', '-t', 'filter',
'-D', 'FORWARD', '-s', mac, '-j', 'DROP'
],
stderr=subprocess.STDOUT,
)
@staticmethod
@logwrap
def restore_vlan(target_dev, vlan):
return subprocess.call(
[
'sudo', 'ebtables', '-t', 'broute', '-D', 'BROUTING', '-i',
target_dev, '-p', '8021Q', '--vlan-id', str(vlan), '-j', 'DROP'
],
stderr=subprocess.STDOUT,
)
@staticmethod
@logwrap
def block_vlan(target_dev, vlan):
return subprocess.check_output(
[
'sudo', 'ebtables', '-t', 'broute', '-A', 'BROUTING', '-i',
target_dev, '-p', '8021Q', '--vlan-id', str(vlan), '-j', 'DROP'
],
stderr=subprocess.STDOUT
)