def test_system_config_simplex_mgmt(): """ Test import of system_config file for AIO-simplex with management configuration""" # Create the path to the system_config file systemfile = os.path.join( os.getcwd(), "controllerconfig/tests/files/", "system_config.simplex_mgmt") _test_system_config(systemfile) # Test MGMT_NETWORK parameters that are not allowed system_config = cr.parse_system_config(systemfile) system_config.set('MGMT_NETWORK', 'GATEWAY', '192.168.42.1') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) system_config = cr.parse_system_config(systemfile) system_config.set('MGMT_NETWORK', 'LOGICAL_INTERFACE', 'LOGICAL_INTERFACE_1') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test overlap with OAM network system_config = cr.parse_system_config(systemfile) system_config.set('MGMT_NETWORK', 'CIDR', '10.10.10.0/24') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test IPv6 management CIDR (not supported) system_config = cr.parse_system_config(systemfile) system_config.set('MGMT_NETWORK', 'CIDR', 'FD01::0000/64') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test management CIDR that is too small system_config = cr.parse_system_config(systemfile) system_config.set('MGMT_NETWORK', 'CIDR', '192.168.42.0/29') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False)
def _test_region_config(tmpdir, inputfile, resultfile, mock_get_wrsroot_sig): """ Test import and generation of answerfile """ mock_get_wrsroot_sig.return_value = None # Create the path to the output file outputfile = os.path.join(str(tmpdir), 'output') # Parse the region_config file region_config = cr.parse_system_config(inputfile) # Dump results for debugging print("Parsed region_config:\n") _dump_config(region_config) # Validate the region config file cr.create_cgcs_config_file(outputfile, region_config, keystone.ServiceList(FAKE_SERVICE_DATA), keystone.EndpointList(FAKE_ENDPOINT_DATA), keystone.DomainList(FAKE_DOMAIN_DATA)) # Make a local copy of the results file local_resultfile = os.path.join(str(tmpdir), 'result') shutil.copyfile(resultfile, local_resultfile) # Do a diff between the output and the expected results print("\n\nDiff of output file vs. expected results file:\n") with open(outputfile) as a, open(local_resultfile) as b: a_lines = a.readlines() b_lines = b.readlines() differ = difflib.Differ() diff = differ.compare(a_lines, b_lines) print(''.join(diff)) # Fail the testcase if the output doesn't match the expected results assert filecmp.cmp(outputfile, local_resultfile) # Now test that configassistant can parse this answerfile. We can't # compare the resulting cgcs_config file because the ordering, spacing # and comments are different between the answerfile generated by # systemconfig and ConfigAssistant. test_answerfile._test_answerfile(tmpdir, outputfile, compare_results=False) # Validate the region config file. # Using onboard validation since the validator's reference version number # is only set at build-time when validating offboard validate(region_config, REGION_CONFIG, None, False)
def _test_system_config(filename): """ Test import and generation of answerfile """ # Parse the system_config file system_config = cr.parse_system_config(filename) # Dump results for debugging print("Parsed system_config:\n") _dump_config(system_config) # Validate the system config file cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) # Validate the system config file. # Using onboard validation since the validator's reference version number # is only set at build-time when validating offboard validate(system_config, DEFAULT_CONFIG, None, False)
def test_region_config_validation(): """ Test detection of various errors in region_config file """ # Create the path to the region_config files simple_regionfile = os.path.join( os.getcwd(), "controllerconfig/tests/files/", "region_config.simple") lag_vlan_regionfile = os.path.join( os.getcwd(), "controllerconfig/tests/files/", "region_config.lag.vlan") # Test detection of non-required CINDER_* parameters region_config = cr.parse_system_config(simple_regionfile) region_config.set('STORAGE', 'CINDER_BACKEND', 'lvm') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, region_config, None, None, None, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(region_config, REGION_CONFIG, None, True) region_config = cr.parse_system_config(simple_regionfile) region_config.set('STORAGE', 'CINDER_DEVICE', '/dev/disk/by-path/pci-0000:00:0d.0-ata-3.0') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, region_config, None, None, None, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(region_config, REGION_CONFIG, None, False) region_config = cr.parse_system_config(simple_regionfile) region_config.set('STORAGE', 'CINDER_STORAGE', '10') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, region_config, None, None, None, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(region_config, REGION_CONFIG, None, False) # Test detection of an invalid PXEBOOT_CIDR region_config = cr.parse_system_config(lag_vlan_regionfile) region_config.set('REGION2_PXEBOOT_NETWORK', 'PXEBOOT_CIDR', '192.168.1.4/24') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, region_config, None, None, None, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(region_config, REGION_CONFIG, None, False) region_config.set('REGION2_PXEBOOT_NETWORK', 'PXEBOOT_CIDR', 'FD00::0000/64') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, region_config, None, None, None, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(region_config, REGION_CONFIG, None, False) region_config.set('REGION2_PXEBOOT_NETWORK', 'PXEBOOT_CIDR', '192.168.1.0/29') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, region_config, None, None, None, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(region_config, REGION_CONFIG, None, False) region_config.remove_option('REGION2_PXEBOOT_NETWORK', 'PXEBOOT_CIDR') with pytest.raises(configparser.NoOptionError): cr.create_cgcs_config_file(None, region_config, None, None, None, validate_only=True) with pytest.raises(configparser.NoOptionError): validate(region_config, REGION_CONFIG, None, False) # Test overlap of CLM_CIDR region_config = cr.parse_system_config(lag_vlan_regionfile) region_config.set('CLM_NETWORK', 'CLM_CIDR', '192.168.203.0/26') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, region_config, None, None, None, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(region_config, REGION_CONFIG, None, False) # Test invalid CLM LAG_MODE region_config = cr.parse_system_config(lag_vlan_regionfile) region_config.set('LOGICAL_INTERFACE_1', 'LAG_MODE', '2') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, region_config, None, None, None, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(region_config, REGION_CONFIG, None, False) # Test CLM_VLAN not allowed region_config = cr.parse_system_config(simple_regionfile) region_config.set('CLM_NETWORK', 'CLM_VLAN', '123') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, region_config, None, None, None, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(region_config, REGION_CONFIG, None, False) # Test CLM_VLAN missing region_config = cr.parse_system_config(lag_vlan_regionfile) region_config.remove_option('CLM_NETWORK', 'CLM_VLAN') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, region_config, None, None, None, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(region_config, REGION_CONFIG, None, False) # Test overlap of BLS_CIDR region_config = cr.parse_system_config(lag_vlan_regionfile) region_config.set('BLS_NETWORK', 'BLS_CIDR', '192.168.203.0/26') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, region_config, None, None, None, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(region_config, REGION_CONFIG, None, False) region_config.set('BLS_NETWORK', 'BLS_CIDR', '192.168.204.0/26') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, region_config, None, None, None, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(region_config, REGION_CONFIG, None, False) # Test invalid BLS LAG_MODE region_config = cr.parse_system_config(lag_vlan_regionfile) region_config.add_section('LOGICAL_INTERFACE_2') region_config.set('LOGICAL_INTERFACE_2', 'LAG_INTERFACE', 'Y') region_config.set('LOGICAL_INTERFACE_2', 'LAG_MODE', '3') region_config.set('LOGICAL_INTERFACE_2', 'INTERFACE_MTU', '1500') region_config.set('LOGICAL_INTERFACE_2', 'INTERFACE_PORTS', 'eth3,eth4') region_config.set('BLS_NETWORK', 'BLS_LOGICAL_INTERFACE', 'LOGICAL_INTERFACE_2') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, region_config, None, None, None, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(region_config, REGION_CONFIG, None, False) # Test BLS_VLAN overlap region_config = cr.parse_system_config(lag_vlan_regionfile) region_config.set('BLS_NETWORK', 'BLS_VLAN', '123') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, region_config, None, None, None, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(region_config, REGION_CONFIG, None, False) # Test overlap of CAN_CIDR region_config = cr.parse_system_config(lag_vlan_regionfile) region_config.set('CAN_NETWORK', 'CAN_CIDR', '192.168.203.0/26') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, region_config, None, None, None, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(region_config, REGION_CONFIG, None, False) region_config.set('CAN_NETWORK', 'CAN_CIDR', '192.168.204.0/26') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, region_config, None, None, None, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(region_config, REGION_CONFIG, None, False) region_config.set('CAN_NETWORK', 'CAN_CIDR', '192.168.205.0/26') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, region_config, None, None, None, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(region_config, REGION_CONFIG, None, False) # Test invalid CAN LAG_MODE region_config = cr.parse_system_config(lag_vlan_regionfile) region_config.add_section('LOGICAL_INTERFACE_2') region_config.set('LOGICAL_INTERFACE_2', 'LAG_INTERFACE', 'Y') region_config.set('LOGICAL_INTERFACE_2', 'LAG_MODE', '3') region_config.set('LOGICAL_INTERFACE_2', 'INTERFACE_MTU', '1500') region_config.set('LOGICAL_INTERFACE_2', 'INTERFACE_PORTS', 'eth3,eth4') region_config.set('CAN_NETWORK', 'CAN_LOGICAL_INTERFACE', 'LOGICAL_INTERFACE_2') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, region_config, None, None, None, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(region_config, REGION_CONFIG, None, False) # Test CAN_VLAN overlap region_config = cr.parse_system_config(lag_vlan_regionfile) region_config.set('CAN_NETWORK', 'CAN_VLAN', '123') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, region_config, None, None, None, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(region_config, REGION_CONFIG, None, False) region_config.set('CAN_NETWORK', 'CAN_VLAN', '124') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, region_config, None, None, None, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(region_config, REGION_CONFIG, None, False) # Test CAN_VLAN missing region_config = cr.parse_system_config(lag_vlan_regionfile) region_config.remove_option('CAN_NETWORK', 'CAN_VLAN') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, region_config, None, None, None, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(region_config, REGION_CONFIG, None, False) # Test missing gateway region_config = cr.parse_system_config(lag_vlan_regionfile) region_config.remove_option('CLM_NETWORK', 'CLM_GATEWAY') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, region_config, None, None, None, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(region_config, REGION_CONFIG, None, False) # Test two gateways region_config = cr.parse_system_config(lag_vlan_regionfile) region_config.set('CAN_NETWORK', 'CAN_GATEWAY', '10.10.10.1') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, region_config, None, None, None, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(region_config, REGION_CONFIG, None, False)
def configure_region(config_file, config_type=REGION_CONFIG): """Configure the region""" # Parse the region/subcloud config file print("Parsing configuration file... ", end=' ') region_config = parse_system_config(config_file) print("DONE") if config_type == SUBCLOUD_CONFIG: # Set defaults in region_config for subclouds set_subcloud_config_defaults(region_config) # Validate the region/subcloud config file print("Validating configuration file... ", end=' ') try: create_cgcs_config_file(None, region_config, None, None, None, config_type=config_type, validate_only=True) except configparser.Error as e: raise ConfigFail("Error parsing configuration file %s: %s" % (config_file, e)) print("DONE") # Bring up management interface to allow us to reach Region 1 print("Configuring management interface... ", end=' ') configure_management_interface(region_config, config_type=config_type) print("DONE") # Get token from keystone print("Retrieving keystone token...", end=' ') sys.stdout.flush() auth_url = region_config.get('SHARED_SERVICES', 'KEYSTONE_ADMINURL') if region_config.has_option('SHARED_SERVICES', 'ADMIN_TENANT_NAME'): auth_project = region_config.get('SHARED_SERVICES', 'ADMIN_TENANT_NAME') else: auth_project = region_config.get('SHARED_SERVICES', 'ADMIN_PROJECT_NAME') auth_user = region_config.get('SHARED_SERVICES', 'ADMIN_USER_NAME') auth_password = region_config.get('SHARED_SERVICES', 'ADMIN_PASSWORD') if region_config.has_option('SHARED_SERVICES', 'ADMIN_USER_DOMAIN'): admin_user_domain = region_config.get('SHARED_SERVICES', 'ADMIN_USER_DOMAIN') else: admin_user_domain = DEFAULT_DOMAIN_NAME if region_config.has_option('SHARED_SERVICES', 'ADMIN_PROJECT_DOMAIN'): admin_project_domain = region_config.get('SHARED_SERVICES', 'ADMIN_PROJECT_DOMAIN') else: admin_project_domain = DEFAULT_DOMAIN_NAME attempts = 0 token = None # Wait for connectivity to region one. It can take some time, especially if # we have LAG on the management network. while not token: token = rutils.get_token(auth_url, auth_project, auth_user, auth_password, admin_user_domain, admin_project_domain) if not token: attempts += 1 if attempts < 10: print("\rRetrieving keystone token...{}".format('.' * attempts), end=' ') sys.stdout.flush() time.sleep(10) else: raise ConfigFail( "Unable to obtain keystone token. Please ensure " "networking and keystone configuration is correct.") print("DONE") # Get services, endpoints, users and domains from keystone print("Retrieving services, endpoints and users from keystone... ", end=' ') region_name = region_config.get('SHARED_SERVICES', 'REGION_NAME') service_name = region_config.get('SHARED_SERVICES', 'KEYSTONE_SERVICE_NAME') service_type = region_config.get('SHARED_SERVICES', 'KEYSTONE_SERVICE_TYPE') api_url = token.get_service_url(region_name, service_name, service_type, "admin").replace('v2.0', 'v3') services = rutils.get_services(token, api_url) endpoints = rutils.get_endpoints(token, api_url) users = rutils.get_users(token, api_url) domains = rutils.get_domains(token, api_url) if not services or not endpoints or not users: raise ConfigFail( "Unable to retrieve services, endpoints or users from keystone. " "Please ensure networking and keystone configuration is correct.") print("DONE") user_config = None if config_type == SUBCLOUD_CONFIG: # Retrieve subcloud configuration from dcmanager print("Retrieving configuration from dcmanager... ", end=' ') dcmanager_url = token.get_service_url('SystemController', 'dcmanager', 'dcmanager', "admin") subcloud_name = region_config.get('REGION_2_SERVICES', 'REGION_NAME') subcloud_management_subnet = region_config.get('MGMT_NETWORK', 'CIDR') hash_string = subcloud_name + subcloud_management_subnet subcloud_config = rutils.get_subcloud_config(token, dcmanager_url, subcloud_name, hash_string) user_config = subcloud_config['users'] print("DONE") try: # Configure missing region one keystone entries create = True # Prepare region configuration for puppet to create keystone identities if (region_config.has_option('REGION_2_SERVICES', 'CREATE') and region_config.get('REGION_2_SERVICES', 'CREATE') == 'Y'): print("Preparing keystone configuration... ", end=' ') # If keystone configuration for this region already in place, # validate it only else: # Validate region one keystone config create = False print("Validating keystone configuration... ", end=' ') validate_region_one_keystone_config(region_config, token, api_url, users, services, endpoints, create, config_type=config_type, user_config=user_config) print("DONE") # validate ldap if it is shared if region_config.has_option('SHARED_SERVICES', 'LDAP_SERVICE_URL'): print("Validating ldap configuration... ", end=' ') validate_region_one_ldap_config(region_config) print("DONE") # Create cgcs_config file print("Creating config apply file... ", end=' ') try: create_cgcs_config_file(TEMP_CGCS_CONFIG_FILE, region_config, services, endpoints, domains, config_type=config_type) except configparser.Error as e: raise ConfigFail("Error parsing configuration file %s: %s" % (config_file, e)) print("DONE") # Configure controller assistant = ConfigAssistant() assistant.configure(TEMP_CGCS_CONFIG_FILE, display_config=False) except ConfigFail as e: print("A configuration failure has occurred.", end=' ') raise e
def test_kubernetes(): """ Test import of system_config file for kubernetes """ # Create the path to the system_config file systemfile = os.path.join(os.getcwd(), "controllerconfig/tests/files/", "system_config.kubernetes") # Test import and generation of answer file _test_system_config(systemfile) # Test CLUSTER_NETWORK start address specified without end address system_config = cr.parse_system_config(systemfile) system_config.set('CLUSTER_NETWORK', 'IP_START_ADDRESS', '192.168.204.2') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test CLUSTER_NETWORK end address specified without start address system_config = cr.parse_system_config(systemfile) system_config.set('CLUSTER_NETWORK', 'IP_END_ADDRESS', '192.168.204.200') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test detection of overspecification of CLUSTER network addresses system_config = cr.parse_system_config(systemfile) system_config.set('CLUSTER_NETWORK', 'IP_FLOATING_ADDRESS', '192.168.206.103') system_config.set('CLUSTER_NETWORK', 'IP_IP_UNIT_0_ADDRESS', '192.168.206.106') system_config.set('CLUSTER_NETWORK', 'IP_IP_UNIT_1_ADDRESS', '192.168.206.109') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test absence of optional DNS configuration system_config = cr.parse_system_config(systemfile) system_config.remove_section('DNS') cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) validate(system_config, DEFAULT_CONFIG, None, False) # Test absence of optional docker proxy configuration system_config = cr.parse_system_config(systemfile) system_config.remove_section('DOCKER_PROXY') cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) validate(system_config, DEFAULT_CONFIG, None, False) # Test absence of optional docker registry configuration system_config = cr.parse_system_config(systemfile) system_config.remove_section('DOCKER_REGISTRY') cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) validate(system_config, DEFAULT_CONFIG, None, False)
def test_system_config_validation(): """ Test detection of various errors in system_config file """ # Create the path to the system_config files simple_systemfile = os.path.join(os.getcwd(), "controllerconfig/tests/files/", "system_config.simple") ipv6_systemfile = os.path.join(os.getcwd(), "controllerconfig/tests/files/", "system_config.ipv6") lag_vlan_systemfile = os.path.join(os.getcwd(), "controllerconfig/tests/files/", "system_config.lag.vlan") ceph_systemfile = os.path.join(os.getcwd(), "controllerconfig/tests/files/", "system_config.ceph") static_addr_systemfile = os.path.join(os.getcwd(), "controllerconfig/tests/files/", "system_config.static_addr") # Test floating outside of OAM_NETWORK CIDR system_config = cr.parse_system_config(ipv6_systemfile) system_config.set('OAM_NETWORK', 'IP_FLOATING_ADDRESS', '5555::5') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test non-ipv6 unit address system_config = cr.parse_system_config(ipv6_systemfile) system_config.set('OAM_NETWORK', 'IP_UNIT_0_ADDRESS', '10.10.10.3') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test missing pxeboot network when using IPv6 management network system_config = cr.parse_system_config(ipv6_systemfile) system_config.remove_section('PXEBOOT_NETWORK') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test ridiculously sized management network system_config = cr.parse_system_config(ipv6_systemfile) system_config.set('MGMT_NETWORK', 'IP_START_ADDRESS', '1234::b:0:0:0') system_config.set('MGMT_NETWORK', 'IP_END_ADDRESS', '1234::b:ffff:ffff:ffff') system_config.remove_option('MGMT_NETWORK', 'IP_FLOATING_ADDRESS') system_config.remove_option('MGMT_NETWORK', 'IP_UNIT_0_ADDRESS') system_config.remove_option('MGMT_NETWORK', 'IP_UNIT_1_ADDRESS') cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) validate(system_config, DEFAULT_CONFIG, None, False) # Test using start/end addresses system_config = cr.parse_system_config(ipv6_systemfile) system_config.set('OAM_NETWORK', 'IP_START_ADDRESS', 'abcd::2') system_config.set('OAM_NETWORK', 'IP_END_ADDRESS', 'abcd::4') system_config.remove_option('OAM_NETWORK', 'IP_FLOATING_ADDRESS') system_config.remove_option('OAM_NETWORK', 'IP_UNIT_0_ADDRESS') system_config.remove_option('OAM_NETWORK', 'IP_UNIT_1_ADDRESS') cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) validate(system_config, DEFAULT_CONFIG, None, False) # Test detection of an invalid PXEBOOT_CIDR system_config = cr.parse_system_config(lag_vlan_systemfile) system_config.set('PXEBOOT_NETWORK', 'PXEBOOT_CIDR', '192.168.1.4/24') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) system_config.set('PXEBOOT_NETWORK', 'PXEBOOT_CIDR', 'FD00::0000/64') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) system_config.set('PXEBOOT_NETWORK', 'PXEBOOT_CIDR', '192.168.1.0/29') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) system_config.remove_option('PXEBOOT_NETWORK', 'PXEBOOT_CIDR') with pytest.raises(configparser.NoOptionError): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(configparser.NoOptionError): validate(system_config, DEFAULT_CONFIG, None, False) # Test overlap of MGMT_NETWORK CIDR system_config = cr.parse_system_config(lag_vlan_systemfile) system_config.set('MGMT_NETWORK', 'CIDR', '192.168.203.0/26') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test invalid MGMT_NETWORK LAG_MODE system_config = cr.parse_system_config(lag_vlan_systemfile) system_config.set('LOGICAL_INTERFACE_1', 'LAG_MODE', '2') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test MGMT_NETWORK VLAN not allowed system_config = cr.parse_system_config(simple_systemfile) system_config.set('MGMT_NETWORK', 'VLAN', '123') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test MGMT_NETWORK VLAN missing system_config = cr.parse_system_config(lag_vlan_systemfile) system_config.remove_option('MGMT_NETWORK', 'VLAN') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test MGMT_NETWORK start address specified without end address system_config = cr.parse_system_config(simple_systemfile) system_config.set('MGMT_NETWORK', 'IP_START_ADDRESS', '192.168.204.2') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test MGMT_NETWORK end address specified without start address system_config = cr.parse_system_config(simple_systemfile) system_config.set('MGMT_NETWORK', 'IP_END_ADDRESS', '192.168.204.200') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test MGMT_NETWORK start and end range does not have enough addresses system_config = cr.parse_system_config(static_addr_systemfile) system_config.set('MGMT_NETWORK', 'IP_START_ADDRESS', '192.168.204.2') system_config.set('MGMT_NETWORK', 'IP_END_ADDRESS', '192.168.204.8') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test MGMT_NETWORK start address not in subnet system_config = cr.parse_system_config(simple_systemfile) system_config.set('MGMT_NETWORK', 'IP_START_ADDRESS', '192.168.200.2') system_config.set('MGMT_NETWORK', 'IP_END_ADDRESS', '192.168.204.254') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test MGMT_NETWORK end address not in subnet system_config = cr.parse_system_config(simple_systemfile) system_config.set('MGMT_NETWORK', 'IP_START_ADDRESS', '192.168.204.2') system_config.set('MGMT_NETWORK', 'IP_END_ADDRESS', '192.168.214.254') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test overlap of INFRA_NETWORK CIDR system_config = cr.parse_system_config(lag_vlan_systemfile) system_config.set('INFRA_NETWORK', 'CIDR', '192.168.203.0/26') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) system_config.set('INFRA_NETWORK', 'CIDR', '192.168.204.0/26') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test invalid INFRA_NETWORK LAG_MODE system_config = cr.parse_system_config(lag_vlan_systemfile) system_config.add_section('LOGICAL_INTERFACE_2') system_config.set('LOGICAL_INTERFACE_2', 'LAG_INTERFACE', 'Y') system_config.set('LOGICAL_INTERFACE_2', 'LAG_MODE', '3') system_config.set('LOGICAL_INTERFACE_2', 'INTERFACE_MTU', '1500') system_config.set('LOGICAL_INTERFACE_2', 'INTERFACE_PORTS', 'eth3,eth4') system_config.set('INFRA_NETWORK', 'LOGICAL_INTERFACE', 'LOGICAL_INTERFACE_2') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test INFRA_NETWORK VLAN overlap system_config = cr.parse_system_config(lag_vlan_systemfile) system_config.set('INFRA_NETWORK', 'VLAN', '123') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test overlap of CLUSTER_NETWORK CIDR system_config = cr.parse_system_config(lag_vlan_systemfile) system_config.set('CLUSTER_NETWORK', 'CIDR', '192.168.203.0/26') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) system_config.set('CLUSTER_NETWORK', 'CIDR', '192.168.204.0/26') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test invalid CLUSTER_NETWORK LAG_MODE system_config = cr.parse_system_config(lag_vlan_systemfile) system_config.add_section('LOGICAL_INTERFACE_2') system_config.set('LOGICAL_INTERFACE_2', 'LAG_INTERFACE', 'Y') system_config.set('LOGICAL_INTERFACE_2', 'LAG_MODE', '3') system_config.set('LOGICAL_INTERFACE_2', 'INTERFACE_MTU', '1500') system_config.set('LOGICAL_INTERFACE_2', 'INTERFACE_PORTS', 'eth3,eth4') system_config.set('CLUSTER_NETWORK', 'LOGICAL_INTERFACE', 'LOGICAL_INTERFACE_2') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test CLUSTER_NETWORK VLAN overlap system_config = cr.parse_system_config(lag_vlan_systemfile) system_config.set('CLUSTER_NETWORK', 'VLAN', '123') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test overlap of OAM_NETWORK CIDR system_config = cr.parse_system_config(lag_vlan_systemfile) system_config.set('OAM_NETWORK', 'CIDR', '192.168.203.0/26') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) system_config.set('OAM_NETWORK', 'CIDR', '192.168.204.0/26') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) system_config.set('OAM_NETWORK', 'CIDR', '192.168.205.0/26') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test invalid OAM_NETWORK LAG_MODE system_config = cr.parse_system_config(lag_vlan_systemfile) system_config.add_section('LOGICAL_INTERFACE_2') system_config.set('LOGICAL_INTERFACE_2', 'LAG_INTERFACE', 'Y') system_config.set('LOGICAL_INTERFACE_2', 'LAG_MODE', '3') system_config.set('LOGICAL_INTERFACE_2', 'INTERFACE_MTU', '1500') system_config.set('LOGICAL_INTERFACE_2', 'INTERFACE_PORTS', 'eth3,eth4') system_config.set('OAM_NETWORK', 'LOGICAL_INTERFACE', 'LOGICAL_INTERFACE_2') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test OAM_NETWORK VLAN overlap system_config = cr.parse_system_config(lag_vlan_systemfile) system_config.set('OAM_NETWORK', 'VLAN', '123') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) system_config.set('OAM_NETWORK', 'VLAN', '124') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test OAM_NETWORK VLAN missing system_config = cr.parse_system_config(lag_vlan_systemfile) system_config.remove_option('OAM_NETWORK', 'VLAN') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test missing gateway system_config = cr.parse_system_config(lag_vlan_systemfile) system_config.remove_option('MGMT_NETWORK', 'GATEWAY') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test two gateways system_config = cr.parse_system_config(lag_vlan_systemfile) system_config.set('OAM_NETWORK', 'GATEWAY', '10.10.10.1') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test detection of unsupported NTP NTP_SERVER system_config = cr.parse_system_config(simple_systemfile) system_config.add_section('NTP') system_config.set('NTP', 'NTP_SERVER_1', '0.pool.ntp.org') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) # Test detection of overspecification of MGMT network addresses system_config = cr.parse_system_config(ceph_systemfile) system_config.set('MGMT_NETWORK', 'IP_FLOATING_ADDRESS', '192.168.204.3') system_config.set('MGMT_NETWORK', 'IP_IP_UNIT_0_ADDRESS', '192.168.204.6') system_config.set('MGMT_NETWORK', 'IP_IP_UNIT_1_ADDRESS', '192.168.204.9') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test detection of overspecification of INFRA network addresses system_config = cr.parse_system_config(ceph_systemfile) system_config.set('INFRA_NETWORK', 'IP_FLOATING_ADDRESS', '192.168.205.103') system_config.set('INFRA_NETWORK', 'IP_IP_UNIT_0_ADDRESS', '192.168.205.106') system_config.set('INFRA_NETWORK', 'IP_IP_UNIT_1_ADDRESS', '192.168.205.109') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test detection of overspecification of OAM network addresses system_config = cr.parse_system_config(ceph_systemfile) system_config.set('MGMT_NETWORK', 'IP_FLOATING_ADDRESS', '10.10.10.2') system_config.set('MGMT_NETWORK', 'IP_IP_UNIT_0_ADDRESS', '10.10.10.3') system_config.set('MGMT_NETWORK', 'IP_IP_UNIT_1_ADDRESS', '10.10.10.4') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False) # Test detection of invalid release version system_config = cr.parse_system_config(ceph_systemfile) system_config.set('VERSION', 'RELEASE', '15.12') with pytest.raises(exceptions.ConfigFail): cr.create_cgcs_config_file(None, system_config, None, None, None, 0, validate_only=True) with pytest.raises(exceptions.ConfigFail): validate(system_config, DEFAULT_CONFIG, None, False)