--- /dev/null
+#!/usr/bin/env python
+
+##############################################################################
+# Copyright (c) 2015 Ericsson AB and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# Unittest for yardstick.benchmark.scenarios.networking.sfc
+
+import mock
+import unittest
+
+from yardstick.benchmark.scenarios.networking import sfc
+
+
+class SfcTestCase(unittest.TestCase):
+
+ def setUp(self):
+ scenario_cfg = dict()
+ context_cfg = dict()
+
+ # Used in Sfc.setup()
+ context_cfg['target'] = dict()
+ context_cfg['target']['user'] = 'root'
+ context_cfg['target']['password'] = 'octopus'
+ context_cfg['target']['ip'] = None
+
+ # Used in Sfc.run()
+ context_cfg['host'] = dict()
+ context_cfg['host']['user'] = 'cirros'
+ context_cfg['host']['password'] = 'cubslose:)'
+ context_cfg['host']['ip'] = None
+ context_cfg['target'] = dict()
+ context_cfg['target']['ip'] = None
+
+ self.sfc = sfc.Sfc(scenario_cfg=scenario_cfg, context_cfg=context_cfg)
+
+ @mock.patch('yardstick.benchmark.scenarios.networking.sfc.ssh')
+ def test_run_for_success(self, mock_ssh):
+ # Mock a successfull SSH in Sfc.setup() and Sfc.run()
+ mock_ssh.SSH().execute.return_value = (0, '100', '')
+
+ result = {}
+ self.sfc.run(result)
+
+
+def main():
+ unittest.main()
+
+if __name__ == '__main__':
+ main()
--- /dev/null
+import pkg_resources
+import logging
+import subprocess
+
+import yardstick.ssh as ssh
+from yardstick.benchmark.scenarios import base
+
+LOG = logging.getLogger(__name__)
+
+
+class Sfc(base.Scenario):
+ ''' SFC scenario class '''
+
+ __scenario_type__ = "sfc"
+
+ PRE_SETUP_SCRIPT = 'sfc_pre_setup.bash'
+ TACKER_SCRIPT = 'sfc_tacker.bash'
+ SERVER_SCRIPT = 'sfc_server.bash'
+ TEARDOWN_SCRIPT = "sfc_teardown.bash"
+
+ def __init__(self, scenario_cfg, context_cfg):
+ self.scenario_cfg = scenario_cfg
+ self.context_cfg = context_cfg
+ self.setup_done = False
+ self.teardown_done = False
+
+ def setup(self):
+ '''scenario setup'''
+ self.tacker_script = pkg_resources.resource_filename(
+ 'yardstick.benchmark.scenarios.networking',
+ Sfc.TACKER_SCRIPT)
+
+ self.server_script = pkg_resources.resource_filename(
+ 'yardstick.benchmark.scenarios.networking',
+ Sfc.SERVER_SCRIPT)
+
+ ''' calling Tacker to instantiate VNFs and Service Chains '''
+ cmd_tacker = "%s" % (self.tacker_script)
+ subprocess.call(cmd_tacker, shell=True)
+
+ target = self.context_cfg['target']
+ target_user = target.get('user', 'root')
+ target_pwd = target.get('password', 'octopus')
+ target_ip = target.get('ip', None)
+
+ ''' webserver start automatically during the vm boot '''
+ LOG.info("user:%s, target:%s", target_user, target_ip)
+ self.server = ssh.SSH(target_user, target_ip, password=target_pwd)
+ self.server.wait(timeout=600)
+ self.server.run("cat > ~/server.sh",
+ stdin=open(self.server_script, "rb"))
+ cmd_server = "sudo bash server.sh"
+ LOG.debug("Executing command: %s", cmd_server)
+ status, stdout, stderr = self.server.execute(cmd_server)
+ LOG.debug("Output server command: %s", status)
+
+ self.setup_done = True
+
+ def run(self, result):
+ ''' Creating client and server VMs to perform the test'''
+ host = self.context_cfg['host']
+ host_user = host.get('user', 'cirros')
+ host_pwd = host.get('password', 'cubswin:)')
+ host_ip = host.get('ip', None)
+
+ LOG.info("user:%s, host:%s", host_user, host_ip)
+ self.client = ssh.SSH(host_user, host_ip, password=host_pwd)
+ self.client.wait(timeout=600)
+
+ if not self.setup_done:
+ self.setup()
+
+ target = self.context_cfg['target']
+ target_ip = target.get('ip', None)
+
+ cmd_client = "curl %s", target_ip
+ LOG.debug("Executing command: %s", cmd_client)
+ result = self.client.execute(cmd_client)
+ LOG.debug("Output client command: %s", result)
+
+ def teardown(self):
+ ''' for scenario teardown remove tacker VNFs, chains and classifiers'''
+ self.teardown_script = pkg_resources.resource_filename(
+ "yardstick.benchmark.scenarios.sfc",
+ Sfc.TEARDOWN_SCRIPT)
+ subprocess.call(self.teardown_script, shell=True)
+ self.teardown_done = True
+
+
+'''def _test():
+
+ internal test function
+ logger = logging.getLogger("Sfc Yardstick")
+ logger.setLevel(logging.DEBUG)
+
+ result = {}
+
+ sfc = Sfc()
+ sfc.setup()
+ sfc.run(result)
+ print result
+ sfc.teardown()
+
+if __name__ == '__main__':
+ _test()'''