From ddac3b6c756d531aaf7a7a39465424c9ee858734 Mon Sep 17 00:00:00 2001 From: "wu.zhihui" Date: Fri, 5 Aug 2016 15:05:30 +0800 Subject: Fetch all compute ips via installer Fuel. 1. Fetch all compute ips via installer Fuel. 2. check the machines' ip. if unassigned, assign one of compute's ip to it. if assigned by test case yaml, check the validation. JIRA: QTIP-98 Change-Id: I5517916c594a14055087134d20c1fe4320b6d707 Signed-off-by: wu.zhihui --- tests/env_setup_test.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'tests') diff --git a/tests/env_setup_test.py b/tests/env_setup_test.py index 9112ff94..cc3c6b60 100644 --- a/tests/env_setup_test.py +++ b/tests/env_setup_test.py @@ -1,6 +1,16 @@ +############################################################################## +# Copyright (c) 2016 ZTE 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 +############################################################################## + import pytest import filecmp from func.env_setup import Env_setup +import mock class TestClass: @@ -31,6 +41,8 @@ class TestClass: print (test_input) print (expected) test_class = Env_setup() + mock_ips = mock.Mock(return_value=["10.20.0.28", "10.20.0.29"]) + test_class.fetch_compute_ips = mock_ips benchmark, vm_para, details, proxy = \ test_class.parse(test_input) assert benchmark == expected[0] @@ -40,12 +52,16 @@ class TestClass: def test_parse_vm_error(self): test_class = Env_setup() + mock_ips = mock.Mock(return_value=["10.20.0.28", "10.20.0.29"]) + test_class.fetch_compute_ips = mock_ips with pytest.raises(KeyError) as excinfo: test_class.parse("tests/test_case/vm_error.yaml") assert "benchmark" in str(excinfo.value) def test_update_ansible(self): test_class = Env_setup() + mock_ips = mock.Mock(return_value=["10.20.0.28", "10.20.0.29"]) + test_class.fetch_compute_ips = mock_ips test_class.parse("tests/test_case/bm_without_proxy.yaml") test_class.update_ansible() result = filecmp.cmp('tests/output/hosts', 'data/hosts') @@ -53,7 +69,40 @@ class TestClass: def test_ping(self, capfd): test_class = Env_setup() + mock_ips = mock.Mock(return_value=["127.0.0.1", "10.20.0.29"]) + test_class.fetch_compute_ips = mock_ips test_class.parse("tests/test_case/bm_ping.yaml") test_class.call_ping_test() resout, reserr = capfd.readouterr() assert '127.0.0.1 is UP' in resout + + def test_check_machine_ips_without_ip(self): + test_class = Env_setup() + mock_ips = mock.Mock(return_value=["10.20.0.28", "10.20.0.29"]) + test_class.fetch_compute_ips = mock_ips + inputs = {"machine_1": {"ip": "", "pw": "", "role": "host"}, + "machine_2": {"ip": "", "pw": "", "role": "host"}} + test_class.check_machine_ips(inputs) + assert inputs["machine_1"]['ip'] in ["10.20.0.28", "10.20.0.29"] + assert inputs["machine_2"]['ip'] in ["10.20.0.28", "10.20.0.29"] + assert inputs["machine_1"]['ip'] != inputs["machine_2"]['ip'] + + def test_check_machine_ips_with_ip(self): + test_class = Env_setup() + mock_ips = mock.Mock(return_value=["10.20.0.28", "10.20.0.29"]) + test_class.fetch_compute_ips = mock_ips + inputs = {"machine_1": {"ip": "10.20.0.28", "pw": "", "role": "host"}, + "machine_2": {"ip": "10.20.0.29", "pw": "", "role": "host"}} + test_class.check_machine_ips(inputs) + assert inputs["machine_1"]['ip'] in ["10.20.0.28", "10.20.0.29"] + assert inputs["machine_2"]['ip'] in ["10.20.0.28", "10.20.0.29"] + assert inputs["machine_1"]['ip'] != inputs["machine_2"]['ip'] + + def test_check_machine_ips_with_invalid_ip(self): + test_class = Env_setup() + mock_ips = mock.Mock(return_value=["10.20.0.28", "10.20.0.29"]) + test_class.fetch_compute_ips = mock_ips + inputs = {"machine_1": {"ip": "10.20.0.3", "pw": "", "role": "host"}, + "machine_2": {"ip": "10.20.0.4", "pw": "", "role": "host"}} + with pytest.raises(RuntimeError): + test_class.check_machine_ips(inputs) -- cgit 1.2.3-korg