Move existing_network context class to proper directory

Unfortunatelly we placed in wrong place existing_network context

Change-Id: I2d9ca785d9c9e90d6198a00c82f0e71b1d866f68
This commit is contained in:
Boris Pavlovic
2015-08-19 14:34:16 -07:00
parent 5a0cc7428f
commit 3381f5db90
2 changed files with 134 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
# 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 rally.common.i18n import _
from rally.common import log as logging
from rally.common import utils
from rally import consts
from rally import osclients
from rally.plugins.openstack.wrappers import network as network_wrapper
from rally.task import context
LOG = logging.getLogger(__name__)
@context.configure(name="existing_network", order=349)
class ExistingNetwork(context.Context):
"""This context supports using existing networks in Rally.
This context should be used on a deployment with existing users.
"""
CONFIG_SCHEMA = {
"type": "object",
"$schema": consts.JSON_SCHEMA,
"additionalProperties": False
}
@utils.log_task_wrapper(LOG.info, _("Enter context: `existing_network`"))
def setup(self):
for user, tenant_id in utils.iterate_per_tenants(
self.context.get("users", [])):
net_wrapper = network_wrapper.wrap(
osclients.Clients(user["endpoint"]),
self.config)
self.context["tenants"][tenant_id]["networks"] = (
net_wrapper.list_networks())
@utils.log_task_wrapper(LOG.info, _("Exit context: `existing_network`"))
def cleanup(self):
"""Networks were not created by Rally, so nothing to do."""

View File

@@ -0,0 +1,81 @@
# 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 mock
from rally.plugins.openstack.context.network import existing_network
from tests.unit import test
CTX = "rally.plugins.openstack.context.network"
class ExistingNetworkTestCase(test.TestCase):
def setUp(self):
super(ExistingNetworkTestCase, self).setUp()
self.config = mock.MagicMock()
self.context = {
"task": mock.MagicMock(),
"users": [
{"id": 1,
"tenant_id": "tenant1",
"endpoint": mock.Mock()},
{"id": 2,
"tenant_id": "tenant2",
"endpoint": mock.Mock()},
],
"tenants": {
"tenant1": {},
"tenant2": {},
},
"config": {
"existing_network": self.config
},
}
@mock.patch("rally.osclients.Clients")
@mock.patch("rally.plugins.openstack.wrappers.network.wrap")
def test_setup(self, mock_network_wrap, mock_clients):
networks = [mock.Mock(), mock.Mock(), mock.Mock()]
net_wrappers = {
"tenant1": mock.Mock(
**{"list_networks.return_value": networks[0:2]}),
"tenant2": mock.Mock(
**{"list_networks.return_value": networks[2:]})
}
mock_network_wrap.side_effect = [net_wrappers["tenant1"],
net_wrappers["tenant2"]]
existing_network.ExistingNetwork(self.context).setup()
mock_clients.assert_has_calls([
mock.call(u["endpoint"]) for u in self.context["users"]])
mock_network_wrap.assert_has_calls([
mock.call(mock_clients.return_value, self.config),
mock.call(mock_clients.return_value, self.config)])
for net_wrapper in net_wrappers.values():
net_wrapper.list_networks.assert_called_once_with()
self.assertDictEqual(
self.context["tenants"],
{
"tenant1": {"networks": networks[0:2]},
"tenant2": {"networks": networks[2:]},
}
)
def test_cleanup(self):
# NOTE(stpierre): Test that cleanup is not abstract
existing_network.ExistingNetwork({"task": mock.MagicMock()}).cleanup()