# Copyright 2013: Mirantis 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. # yardstick comment: this file is a modified copy of # rally/tests/unit/common/test_sshutils.py from __future__ import absolute_import import os import socket import unittest from io import StringIO import mock from oslo_utils import encodeutils from yardstick import ssh class FakeParamikoException(Exception): pass class SSHTestCase(unittest.TestCase): """Test all small SSH methods.""" def setUp(self): super(SSHTestCase, self).setUp() self.test_client = ssh.SSH("root", "example.net") @mock.patch("yardstick.ssh.SSH._get_pkey") def test_construct(self, mock_ssh__get_pkey): mock_ssh__get_pkey.return_value = "pkey" test_ssh = ssh.SSH("root", "example.net", port=33, pkey="key", key_filename="kf", password="secret") mock_ssh__get_pkey.assert_called_once_with("key") self.assertEqual("root", test_ssh.user) self.assertEqual("example.net", test_ssh.host) self.assertEqual(33, test_ssh.port) self.assertEqual("pkey", test_ssh.pkey) self.assertEqual("kf", test_ssh.key_filename) self.assertEqual("secret", test_ssh.password) def test_construct_default(self): self.assertEqual("root", self.test_client.user) self.assertEqual("example.net", self.test_client.host) self.assertEqual(22, self.test_client.port) self.assertIsNone(self.test_client.pkey) self.assertIsNone(self.test_client.key_filename) self.assertIsNone(self.test_client.password) @mock.patch("yardstick.ssh.paramiko") def test__get_pkey_invalid(self, mock_paramiko): mock_paramiko.SSHException = FakeParamikoException rsa = mock_paramiko.rsakey.RSAKey dss = mock_paramiko.dsskey.DSSKey rsa.from_private_key.side_effect = mock_paramiko.SSHException dss.from_private_key.side_effect = mock_paramiko.SSHException self.assertRaises(ssh.SSHError, self.test_client._get_pkey, "key") @mock.patch("yardstick.ssh.six.moves.StringIO") @mock.patch("yardstick.ssh.paramiko") def test__get_pkey_dss(self, mock_paramiko, mock_string_io): mock_paramiko.SSHException = FakeParamikoException mock_string_io.return_value = "string_key" mock_paramiko.dsskey.DSSKey.from_private_key.return_value = "dss_key" rsa = mock_paramiko.rsakey.RSAKey rsa.from_private_key.side_effect = mock_paramiko.SSHException key = self.test_client._get_pkey("key") dss_calls = mock_paramiko.dsskey.DSSKey.from_private_key.mock_calls self.assertEqual([mock.call("string_key")], dss_calls) self.assertEqual(key, "dss_key") mock_string_io.assert_called_once_with("key") @mock.patch("yardstick.ssh.six.moves.StringIO") @mock.patch("yardstick.ssh.paramiko") def test__get_pkey_rsa(self, mock_paramiko, mock_string_io): mock_paramiko.SSHException = FakeParamikoException mock_string_io.return_value = "string_key" mock_paramiko.rsakey.RSAKey.from_private_key.return_value = "rsa_key" dss = mock_paramiko.dsskey.DSSKey dss.from_private_key.side_effect = mock_paramiko.SSHException key = self.test_client._get_pkey("key") rsa_calls = mock_paramiko.rsakey.RSAKey.from_private_key.mock_calls self.assertEqual([mock.call("string_key")], rsa_calls) self.assertEqual(key, "rsa_key") mock_string_io.assert_called_once_with("key") @mock.patch("yardstick.ssh.SSH._get_pkey") @mock.patch("yardstick.ssh.paramiko") def test__get_client(self, mock_paramiko, mock_ssh__get_pkey): mock_ssh__get_pkey.return_value = "key" fake_client = mock.Mock() mock_paramiko.SSHClient.return_value = fake_client mock_paramiko.AutoAddPolicy.return_value = "autoadd" test_ssh = ssh.SSH("admin", "example.net", pkey="key") client = test_ssh._get_client() self.assertEqual(fake_client, client) client_calls = [ mock.call.set_missing_host_key_policy("autoadd"), mock.call.connect("example.net", username="admin", port=22, pkey="key", key_filename=None, password=None, allow_agent=False, look_for_keys=False, timeout=1), ] self.assertEqual(client_calls, client.mock_calls) def test_close(self): with mock.patch.object(self.test_client, "_client") as m_client: self.test_client.close() m_client.close.assert_called_once_with() self.assertFalse(self.test_client._client) @mock.patch("yardstick.ssh.six.moves.StringIO") def test_execute(self, mock_string_io): mock_string_io.side_effect = stdio = [mock.Mock(), mock.Mock()] stdio[0].read.return_value = "stdout fake data" stdio[1].read.return_value = "stderr fake data" with mock.patch.object(self.test_client, "run", return_value=0)\ as mock_run: status, stdout, stderr = self.test_client.execute( "cmd", stdin="fake_stdin", timeout=43) mock_run.assert_called_once_with( "cmd", stdin="fake_stdin", stdout=stdio[0], stderr=stdio[1], timeout=43, raise_on_error=False) self.assertEqual(0, status) self.assertEqual("stdout fake data", stdout) self.assertEqual("stderr fake data", stderr) @mock.patch("yardstick.ssh.time") def test_wait_timeout(self, mock_time): mock_time.time.side_effect = [1, 50, 150] self.test_client.execute = mock.Mock(side_effect=[ssh.SSHError,
================================
OPNFV traffic profile guidelines
================================
.. contents::
.. _introduction:
------------
Introduction
------------
In order to have consistent testing profiles, it has been suggested to define and store traffic profiles.
These profiles shall be based on operator representative scenario.
These reference profiles may be used by any test projects, unitary, functional or performance tests.
It is possible to adapt them to specific testcases.
It is recommended to use them in order to avoid getting as many profiles as tests.
It should be helpful to compare the results of test scenario.
.. _howto:
-------------------------
How to use these profiles
-------------------------
The directory of the traffic profiles may be described as follow::
├── commons
├── ims
│ └── readme.rst
├── mobile
│ └── readme.rst
└── traffic-profile-guidelines.rst
the readme.rst details the profile.
.. _overview:
------------------------
Traffic profile overview
------------------------
The current profiles are available:
* Mobile traffic
* IMS residential traffic
* ...
Mobile traffic
==============
IMS residential traffic
=======================
.. _reference:
---------
reference
---------