Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[config/show]: split vlan into separate file #1038

Merged
merged 7 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions show/bgp_frr_v4.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import click
from show.main import AliasedGroup, ip, run_command, get_bgp_summary_extended

import utilities_common.cli as clicommon

from show.main import ip, run_command, get_bgp_summary_extended


###############################################################################
Expand All @@ -9,7 +12,7 @@
###############################################################################


@ip.group(cls=AliasedGroup)
@ip.group(cls=clicommon.AliasedGroup)
def bgp():
"""Show IPv4 BGP (Border Gateway Protocol) information"""
pass
Expand Down
6 changes: 4 additions & 2 deletions show/bgp_frr_v6.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import click
from show.main import AliasedGroup, ipv6, run_command, get_bgp_summary_extended

import utilities_common.cli as clicommon
from show.main import ipv6, run_command, get_bgp_summary_extended


###############################################################################
Expand All @@ -9,7 +11,7 @@
###############################################################################


@ipv6.group(cls=AliasedGroup)
@ipv6.group(cls=clicommon.AliasedGroup)
def bgp():
"""Show IPv6 BGP (Border Gateway Protocol) information"""
pass
Expand Down
29 changes: 0 additions & 29 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,6 @@

VLAN_SUB_INTERFACE_SEPARATOR = '.'

try:
# noinspection PyPep8Naming
import ConfigParser as configparser
except ImportError:
# noinspection PyUnresolvedReferences
import configparser


# This is from the aliases example:
# https://github.com/pallets/click/blob/57c6f09611fc47ca80db0bd010f05998b3c0aa95/examples/aliases/aliases.py
class Config(object):
"""Object to hold CLI config"""

def __init__(self):
self.path = os.getcwd()
self.aliases = {}

def read_config(self, filename):
parser = configparser.RawConfigParser()
parser.read([filename])
try:
self.aliases.update(parser.items('aliases'))
except configparser.NoSectionError:
pass


# Global Config object
_config = None

# To be enhanced. Routing-stack information should be collected from a global
# location (configdb?), so that we prevent the continous execution of this
# bash oneliner. To be revisited once routing-stack info is tracked somewhere.
Expand Down
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import sys

import mock
import click
import pytest

import mock_tables.dbconnector
Expand Down
8 changes: 7 additions & 1 deletion tests/vlan_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ def setup_class(cls):
os.environ['UTILITIES_UNIT_TESTING'] = "1"
print("SETUP")

def test_show_vlan(self):
runner = CliRunner()
result = runner.invoke(show.cli.commands["vlan"], [])
print(result.exit_code)
print(result.output)
assert result.exit_code == 0

def test_show_vlan_brief(self):
runner = CliRunner()
result = runner.invoke(show.cli.commands["vlan"].commands["brief"], [])
Expand Down Expand Up @@ -260,7 +267,6 @@ def test_config_vlan_del_vlan(self):

def test_config_vlan_del_nonexist_vlan_member(self):
runner = CliRunner()
db = Db()

result = runner.invoke(config.config.commands["vlan"].commands["member"].commands["del"], \
["1000", "Ethernet0"])
Expand Down
27 changes: 27 additions & 0 deletions utilities_common/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,33 @@ def get_command(self, ctx, cmd_name):

ctx.fail('Too many matches: %s' % ', '.join(sorted(matches)))

try:
# noinspection PyPep8Naming
import ConfigParser as configparser
except ImportError:
# noinspection PyUnresolvedReferences
import configparser

# This is from the aliases example:
# https://github.com/pallets/click/blob/57c6f09611fc47ca80db0bd010f05998b3c0aa95/examples/aliases/aliases.py
class Config(object):
"""Object to hold CLI config"""

def __init__(self):
self.path = os.getcwd()
self.aliases = {}

def read_config(self, filename):
parser = configparser.RawConfigParser()
parser.read([filename])
try:
self.aliases.update(parser.items('aliases'))
except configparser.NoSectionError:
pass

# Global Config object
_config = None

class AliasedGroup(click.Group):
"""This subclass of click.Group supports abbreviations and
looking up aliases in a config file with a bit of magic.
Expand Down