Init agent, common, unittest.
This commit is contained in:
parent
0dfa3b2e1a
commit
2a69a78d58
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
*.pyc
|
||||||
|
stetho.egg-info/
|
||||||
|
build/
|
||||||
|
dist/
|
28
setup.py
Normal file
28
setup.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# Copyright 2015 UnitedStack, Inc.
|
||||||
|
# All Rights Reserved.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
|
setup(name='stetho',
|
||||||
|
version="0.1.0",
|
||||||
|
packages = find_packages(),
|
||||||
|
zip_safe = False,
|
||||||
|
description = "stetho",
|
||||||
|
author = "UnitedStackSDN",
|
||||||
|
author_email = "unitedstack-sdn@googlegroups.com",
|
||||||
|
license = "APL",
|
||||||
|
keywords = ("stetho", "egg"),
|
||||||
|
platforms = "Independant",
|
||||||
|
url = "https://www.ustack.com")
|
0
stetho/agent/__init__.py
Normal file
0
stetho/agent/__init__.py
Normal file
77
stetho/agent/agent.py
Normal file
77
stetho/agent/agent.py
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
# Copyright 2015 UnitedStack, Inc.
|
||||||
|
# All Rights Reserved.
|
||||||
|
#
|
||||||
|
# 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 os
|
||||||
|
import sys
|
||||||
|
import zerorpc
|
||||||
|
|
||||||
|
# Listening endpoint
|
||||||
|
LISTEN_PROTOCOL = 'tcp'
|
||||||
|
LISTEN_ADDR = '0.0.0.0'
|
||||||
|
LISTEN_PORT = '9698'
|
||||||
|
|
||||||
|
|
||||||
|
class AgentApi(object):
|
||||||
|
"""Agent Api.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def check_ports_on_br(self, bridge, ports=[]):
|
||||||
|
"""ovs-vsctl list-ports bridge
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def ping(self, ips, boardcast=False,
|
||||||
|
count=2, timeout=2, interface=None):
|
||||||
|
"""ping host -c 2 -W 2
|
||||||
|
packet loss
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def add_vlan_to_interface(self, interface, vlan_id):
|
||||||
|
"""ip link add link
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def get_interface_info(self, interface):
|
||||||
|
"""ifconfig
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def setup_link(self, interface, cidr):
|
||||||
|
"""IP addr and ifup
|
||||||
|
check net_cidr
|
||||||
|
10.0.0.0/24 -> 10.0.0.64/24
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def teardown_link(self, interface):
|
||||||
|
"""ip link
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# log
|
||||||
|
args = sys.argv[1:]
|
||||||
|
s = zerorpc.Server(AgentApi())
|
||||||
|
endpoint = '%s://%s:%s' % (LISTEN_PROTOCOL, LISTEN_ADDR, LISTEN_PORT)
|
||||||
|
s.bind(endpoint)
|
||||||
|
s.run()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
0
stetho/agent/common/__init__.py
Normal file
0
stetho/agent/common/__init__.py
Normal file
31
stetho/agent/common/utils.py
Normal file
31
stetho/agent/common/utils.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# Copyright 2015 UnitedStack, Inc.
|
||||||
|
# All Rights Reserved.
|
||||||
|
#
|
||||||
|
# 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 time
|
||||||
|
import shlex
|
||||||
|
import subprocess
|
||||||
|
from stetho.common import log
|
||||||
|
|
||||||
|
log = log.get_logger('/opt/stack/logs/stetho-agent.log')
|
||||||
|
|
||||||
|
|
||||||
|
def execute(cmd, time=None, shell=False):
|
||||||
|
try:
|
||||||
|
log.info(cmd)
|
||||||
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=shell)
|
||||||
|
out = p.stdout.readlines()
|
||||||
|
return [line.strip() for line in out]
|
||||||
|
except Exception as e:
|
||||||
|
log.exception(e)
|
0
stetho/common/__init__.py
Normal file
0
stetho/common/__init__.py
Normal file
28
stetho/common/log.py
Normal file
28
stetho/common/log.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# Copyright 2015 UnitedStack, Inc.
|
||||||
|
# All Rights Reserved.
|
||||||
|
#
|
||||||
|
# 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 logging
|
||||||
|
|
||||||
|
FORMAT = '%(asctime)s %(filename)s %(levelname)s %(message)s'
|
||||||
|
DATEFMT = '%d %b %Y %H:%M:%S'
|
||||||
|
|
||||||
|
|
||||||
|
def get_logger(filename, format=FORMAT,
|
||||||
|
datefmt=DATEFMT, filemod='a+',
|
||||||
|
level=logging.DEBUG):
|
||||||
|
logging.basicConfig(level=level, format=format, datefmt=datefmt,
|
||||||
|
filename=filename, filemod=filemod)
|
||||||
|
log = logging.getLogger()
|
||||||
|
return log
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
0
tests/unit/__init__.py
Normal file
0
tests/unit/__init__.py
Normal file
0
tests/unit/agent/__init__.py
Normal file
0
tests/unit/agent/__init__.py
Normal file
0
tests/unit/agent/common/__init__.py
Normal file
0
tests/unit/agent/common/__init__.py
Normal file
38
tests/unit/agent/common/test_utils.py
Normal file
38
tests/unit/agent/common/test_utils.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# Copyright 2015 UnitedStack, Inc.
|
||||||
|
# All Rights Reserved.
|
||||||
|
#
|
||||||
|
# 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 unittest
|
||||||
|
|
||||||
|
from stetho.agent.common import utils
|
||||||
|
|
||||||
|
|
||||||
|
class TestUtils(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.test_file = self.get_temp_file_path('test_execute.tmp')
|
||||||
|
open(self.test_file, 'w+').close()
|
||||||
|
|
||||||
|
def test_execute(self):
|
||||||
|
expected = "%s\n" % self.test_file
|
||||||
|
result = utils.execute(["ls", self.test_file])
|
||||||
|
self.assertEqual(result.pop(), expected.strip('\n'))
|
||||||
|
|
||||||
|
def get_temp_file_path(self, filename, root=None):
|
||||||
|
root = '/tmp/%s'
|
||||||
|
return root % filename
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
14
tests/unit/agent/test_agent.py
Normal file
14
tests/unit/agent/test_agent.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# Copyright 2015 UnitedStack, Inc.
|
||||||
|
# All Rights Reserved.
|
||||||
|
#
|
||||||
|
# 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.
|
0
tests/unit/common/__init__.py
Normal file
0
tests/unit/common/__init__.py
Normal file
28
tests/unit/common/test_log.py
Normal file
28
tests/unit/common/test_log.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# Copyright 2015 UnitedStack, Inc.
|
||||||
|
# All Rights Reserved.
|
||||||
|
#
|
||||||
|
# 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 unittest
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from stetho.common import log
|
||||||
|
|
||||||
|
|
||||||
|
class TestLog(unittest.TestCase):
|
||||||
|
def test_get_logger(self):
|
||||||
|
log_test = log.get_logger(filename='test')
|
||||||
|
self.assertEqual(type(log_test), type(logging.getLogger()))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
x
Reference in New Issue
Block a user