Browse Source

Merge "add test_update_vm_ip add test_vm_associated_2vn"

Jenkins 2 years ago
parent
commit
9e798791e5
1 changed files with 59 additions and 1 deletions
  1. 59
    1
      plugin_test/vapor/vapor/tests/common/test_base.py

+ 59
- 1
plugin_test/vapor/vapor/tests/common/test_base.py View File

@@ -11,7 +11,7 @@
11 11
 # under the License.
12 12
 
13 13
 import sys
14
-
14
+from ipaddress import ip_address, ip_network
15 15
 from hamcrest import (assert_that, calling, raises, contains_string, has_item,
16 16
                       has_entry, is_not, empty, equal_to, all_of)  # noqa H301
17 17
 from neutronclient.common import exceptions as neutron_exceptions
@@ -26,6 +26,7 @@ from vapor.helpers import agent_steps
26 26
 from vapor.helpers import asserts
27 27
 from vapor.helpers import contrail_status, policy, connectivity
28 28
 from vapor import settings
29
+from vapor.helpers import contrail_status, nodes_steps
29 30
 
30 31
 
31 32
 def test_network_deleting_with_server(network, server, contrail_api_client):
@@ -535,3 +536,60 @@ def test_policy_between_vns_diff_proj(different_tenants_resources,
535 536
             server_floating_ip['floating_ip_address'],
536 537
             server_ssh,
537 538
             timeout=settings.SECURITY_GROUP_APPLY_TIMEOUT)
539
+
540
+
541
+def test_vm_associated_2vn(cirros_image, flavor, security_group,
542
+                           contrail_2_networks, server_steps):
543
+    """Test to validate a VM associated with two VNs.
544
+    Test steps:
545
+        1. Create 2 VNs.
546
+        2. Launch a VM such that it has address from both the VNs.
547
+    Pass criteria:
548
+        VM should get both the IPs.
549
+    """
550
+    server = server_steps.create_servers(
551
+        image=cirros_image,
552
+        flavor=flavor,
553
+        networks=contrail_2_networks.networks,
554
+        security_groups=[security_group])[0]
555
+    server_ips = server_steps.get_ips(server)
556
+    nets = {net['name'] for net in contrail_2_networks.networks}
557
+    server_nets = {ip['net'] for addr, ip in server_ips.items()}
558
+    server_ips = {ip_address(addr) for addr, ip in server_ips.items()}
559
+    cidrs = {ip_network(subnet['cidr'])
560
+             for subnet in contrail_2_networks.subnets}
561
+    assert_that(nets, equal_to(server_nets))
562
+    # Check each CIDR for each IP
563
+    ips_in_cidr = {ip for ip in server_ips for cidr in cidrs if ip in cidr}
564
+    assert_that(server_ips, equal_to(ips_in_cidr))
565
+
566
+
567
+def test_update_vm_ip(server, subnet, port_steps, server_steps):
568
+    """Test to validate that updating the IP address of the VM fails.
569
+    Test steps:
570
+        1. Create a VM in a VN.
571
+        2. Try to update the IP of the VM.
572
+    Pass criteria:
573
+        Modification of fixed IP will not be allowed.
574
+        Proper error should be observed.
575
+    """
576
+    server_fixed_ip = server_steps.get_fixed_ip(server)
577
+    # Find new IP address from server's network
578
+    server_fixed_ip_new = ''
579
+    for net_ip in ip_network(subnet['cidr']).hosts():
580
+        if str(net_ip) != server_fixed_ip:
581
+            server_fixed_ip_new = str(net_ip)
582
+            break
583
+
584
+    server_port = port_steps.get_port(
585
+        device_owner=stepler_config.PORT_DEVICE_OWNER_SERVER,
586
+        device_id=server.id)
587
+    port_dict = {
588
+        'fixed_ips': [{'subnet_id': subnet['id'],
589
+                       'ip_address': server_fixed_ip_new}]
590
+    }
591
+    assert_that(
592
+        calling(port_steps.update).with_args(server_port,
593
+                                             check=False,
594
+                                             **port_dict),
595
+        raises(neutron_exceptions.BadRequest))

Loading…
Cancel
Save