~ubuntu-branches/ubuntu/precise/network-manager/precise

« back to all changes in this revision

Viewing changes to src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2012-02-09 16:45:41 UTC
  • mfrom: (1.1.53)
  • Revision ID: package-import@ubuntu.com-20120209164541-4h90zknlsfdb7x35
Tags: 0.9.2.0+git201202091925.c721477-0ubuntu1
* upstream snapshot 2012-02-09 19:25:59 (GMT)
  + c721477d11d4fe144111d6d2eec8f93f2e9186c9
* debian/patches/avoid-periodic-disk-wakeups.patch: refreshed.
* debian/patches/nl3-default-ip6-route.patch: refreshed.
* debian/libnm-glib4.symbols: add symbols:
  + nm_active_connection_get_master@Base
  + nm_client_new_async@Base
  + nm_client_new_finish@Base
  + nm_remote_settings_new_async@Base
  + nm_remote_settings_new_finish@Base
  + nm_device_get_state_reason@Base
* debian/libnm-util2.symbols: add symbols:
  + nm_setting_802_1x_get_pac_file@Base
  + nm_setting_infiniband_get_transport_mode@Base

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <unistd.h>
24
24
#include <string.h>
25
25
#include <netinet/ether.h>
 
26
#include <linux/if_infiniband.h>
26
27
#include <netinet/in.h>
27
28
#include <arpa/inet.h>
28
29
#include <sys/socket.h>
11774
11775
        g_free (route6file);
11775
11776
}
11776
11777
 
 
11778
#define TEST_IFCFG_INFINIBAND TEST_IFCFG_DIR"/network-scripts/ifcfg-test-infiniband"
 
11779
 
 
11780
static void
 
11781
test_read_infiniband (void)
 
11782
{
 
11783
        NMConnection *connection;
 
11784
        NMSettingInfiniband *s_infiniband;
 
11785
        char *unmanaged = NULL;
 
11786
        char *keyfile = NULL;
 
11787
        char *routefile = NULL;
 
11788
        char *route6file = NULL;
 
11789
        gboolean ignore_error = FALSE;
 
11790
        GError *error = NULL;
 
11791
        const GByteArray *array;
 
11792
        char expected_mac_address[INFINIBAND_ALEN] = { 0x80, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22 };
 
11793
        const char *transport_mode;
 
11794
 
 
11795
        connection = connection_from_file (TEST_IFCFG_INFINIBAND,
 
11796
                                           NULL,
 
11797
                                           TYPE_INFINIBAND,
 
11798
                                           NULL,
 
11799
                                           &unmanaged,
 
11800
                                           &keyfile,
 
11801
                                           &routefile,
 
11802
                                           &route6file,
 
11803
                                           &error,
 
11804
                                           &ignore_error);
 
11805
        ASSERT (connection != NULL,
 
11806
                "infiniband-read", "failed to read %s: %s", TEST_IFCFG_INFINIBAND, error->message);
 
11807
 
 
11808
        ASSERT (nm_connection_verify (connection, &error),
 
11809
                "infiniband-verify", "failed to verify %s: %s", TEST_IFCFG_INFINIBAND, error->message);
 
11810
 
 
11811
        ASSERT (unmanaged == NULL,
 
11812
                "infiniband-verify", "failed to verify %s: unexpected unmanaged value", TEST_IFCFG_INFINIBAND);
 
11813
 
 
11814
        /* ===== INFINIBAND SETTING ===== */
 
11815
 
 
11816
        s_infiniband = nm_connection_get_setting_infiniband (connection);
 
11817
        ASSERT (s_infiniband != NULL,
 
11818
                "infiniband-verify-wired", "failed to verify %s: missing %s setting",
 
11819
                TEST_IFCFG_INFINIBAND,
 
11820
                NM_SETTING_INFINIBAND_SETTING_NAME);
 
11821
 
 
11822
        /* MAC address */
 
11823
        array = nm_setting_infiniband_get_mac_address (s_infiniband);
 
11824
        ASSERT (array != NULL,
 
11825
                "infiniband-verify-infiniband", "failed to verify %s: missing %s / %s key",
 
11826
                TEST_IFCFG_INFINIBAND,
 
11827
                NM_SETTING_INFINIBAND_SETTING_NAME,
 
11828
                NM_SETTING_INFINIBAND_MAC_ADDRESS);
 
11829
        ASSERT (array->len == INFINIBAND_ALEN,
 
11830
                "infiniband-verify-infiniband", "failed to verify %s: unexpected %s / %s key value length",
 
11831
                TEST_IFCFG_INFINIBAND,
 
11832
                NM_SETTING_INFINIBAND_SETTING_NAME,
 
11833
                NM_SETTING_INFINIBAND_MAC_ADDRESS);
 
11834
        ASSERT (memcmp (array->data, &expected_mac_address[0], sizeof (expected_mac_address)) == 0,
 
11835
                "infiniband-verify-infiniband", "failed to verify %s: unexpected %s / %s key value",
 
11836
                TEST_IFCFG_INFINIBAND,
 
11837
                NM_SETTING_INFINIBAND_SETTING_NAME,
 
11838
                NM_SETTING_INFINIBAND_MAC_ADDRESS);
 
11839
 
 
11840
        /* Transport mode */
 
11841
        transport_mode = nm_setting_infiniband_get_transport_mode (s_infiniband);
 
11842
        ASSERT (transport_mode != NULL,
 
11843
                "infiniband-verify-infiniband", "failed to verify %s: missing %s / %s key",
 
11844
                TEST_IFCFG_INFINIBAND,
 
11845
                NM_SETTING_INFINIBAND_SETTING_NAME,
 
11846
                NM_SETTING_INFINIBAND_TRANSPORT_MODE);
 
11847
        ASSERT (strcmp (transport_mode, "connected") == 0,
 
11848
                "infiniband-verify-infiniband", "failed to verify %s: unexpected %s / %s key value",
 
11849
                TEST_IFCFG_INFINIBAND,
 
11850
                NM_SETTING_INFINIBAND_SETTING_NAME,
 
11851
                NM_SETTING_INFINIBAND_TRANSPORT_MODE);
 
11852
 
 
11853
        g_free (unmanaged);
 
11854
        g_free (keyfile);
 
11855
        g_free (routefile);
 
11856
        g_free (route6file);
 
11857
        g_object_unref (connection);
 
11858
}
 
11859
 
 
11860
static void
 
11861
test_write_infiniband (void)
 
11862
{
 
11863
        NMConnection *connection;
 
11864
        NMConnection *reread;
 
11865
        NMSettingConnection *s_con;
 
11866
        NMSettingInfiniband *s_infiniband;
 
11867
        NMSettingIP4Config *s_ip4;
 
11868
        NMSettingIP6Config *s_ip6;
 
11869
        unsigned char tmpmac[INFINIBAND_ALEN] = { 0x80, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22 };
 
11870
        GByteArray *mac;
 
11871
        guint32 mtu = 65520;
 
11872
        char *uuid;
 
11873
        const guint32 ip1 = htonl (0x01010103);
 
11874
        const guint32 gw = htonl (0x01010101);
 
11875
        const guint32 prefix = 24;
 
11876
        NMIP4Address *addr;
 
11877
        gboolean success;
 
11878
        GError *error = NULL;
 
11879
        char *testfile = NULL;
 
11880
        char *unmanaged = NULL;
 
11881
        char *keyfile = NULL;
 
11882
        char *routefile = NULL;
 
11883
        char *route6file = NULL;
 
11884
        gboolean ignore_error = FALSE;
 
11885
 
 
11886
        connection = nm_connection_new ();
 
11887
        ASSERT (connection != NULL,
 
11888
                "infiniband-write", "failed to allocate new connection");
 
11889
 
 
11890
        /* Connection setting */
 
11891
        s_con = (NMSettingConnection *) nm_setting_connection_new ();
 
11892
        ASSERT (s_con != NULL,
 
11893
                "infiniband-write", "failed to allocate new %s setting",
 
11894
                NM_SETTING_CONNECTION_SETTING_NAME);
 
11895
        nm_connection_add_setting (connection, NM_SETTING (s_con));
 
11896
 
 
11897
        uuid = nm_utils_uuid_generate ();
 
11898
        g_object_set (s_con,
 
11899
                      NM_SETTING_CONNECTION_ID, "Test Write Infiniband",
 
11900
                      NM_SETTING_CONNECTION_UUID, uuid,
 
11901
                      NM_SETTING_CONNECTION_AUTOCONNECT, TRUE,
 
11902
                      NM_SETTING_CONNECTION_TYPE, NM_SETTING_INFINIBAND_SETTING_NAME,
 
11903
                      NULL);
 
11904
        g_free (uuid);
 
11905
 
 
11906
        /* Infiniband setting */
 
11907
        s_infiniband = (NMSettingInfiniband *) nm_setting_infiniband_new ();
 
11908
        ASSERT (s_infiniband != NULL,
 
11909
                "infiniband-write", "failed to allocate new %s setting",
 
11910
                NM_SETTING_INFINIBAND_SETTING_NAME);
 
11911
        nm_connection_add_setting (connection, NM_SETTING (s_infiniband));
 
11912
 
 
11913
        mac = g_byte_array_sized_new (sizeof (tmpmac));
 
11914
        g_byte_array_append (mac, &tmpmac[0], sizeof (tmpmac));
 
11915
 
 
11916
        g_object_set (s_infiniband,
 
11917
                      NM_SETTING_INFINIBAND_MAC_ADDRESS, mac,
 
11918
                      NM_SETTING_INFINIBAND_MTU, mtu,
 
11919
                      NM_SETTING_INFINIBAND_TRANSPORT_MODE, "connected",
 
11920
                      NULL);
 
11921
        g_byte_array_free (mac, TRUE);
 
11922
 
 
11923
        /* IP4 setting */
 
11924
        s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
 
11925
        ASSERT (s_ip4 != NULL,
 
11926
                        "infiniband-write", "failed to allocate new %s setting",
 
11927
                        NM_SETTING_IP4_CONFIG_SETTING_NAME);
 
11928
        nm_connection_add_setting (connection, NM_SETTING (s_ip4));
 
11929
 
 
11930
        g_object_set (s_ip4,
 
11931
                      NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
 
11932
                      NM_SETTING_IP4_CONFIG_MAY_FAIL, TRUE,
 
11933
                      NULL);
 
11934
 
 
11935
        addr = nm_ip4_address_new ();
 
11936
        nm_ip4_address_set_address (addr, ip1);
 
11937
        nm_ip4_address_set_prefix (addr, prefix);
 
11938
        nm_ip4_address_set_gateway (addr, gw);
 
11939
        nm_setting_ip4_config_add_address (s_ip4, addr);
 
11940
        nm_ip4_address_unref (addr);
 
11941
 
 
11942
        /* IP6 setting */
 
11943
        s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
 
11944
        ASSERT (s_ip6 != NULL,
 
11945
                "wired-static-write", "failed to allocate new %s setting",
 
11946
                NM_SETTING_IP6_CONFIG_SETTING_NAME);
 
11947
        nm_connection_add_setting (connection, NM_SETTING (s_ip6));
 
11948
 
 
11949
        g_object_set (s_ip6,
 
11950
                      NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
 
11951
                      NULL);
 
11952
 
 
11953
        ASSERT (nm_connection_verify (connection, &error) == TRUE,
 
11954
                "infiniband-write", "failed to verify connection: %s",
 
11955
                (error && error->message) ? error->message : "(unknown)");
 
11956
 
 
11957
        /* Save the ifcfg */
 
11958
        success = writer_new_connection (connection,
 
11959
                                         TEST_SCRATCH_DIR "/network-scripts/",
 
11960
                                         &testfile,
 
11961
                                         &error);
 
11962
        ASSERT (success == TRUE,
 
11963
                "infiniband-write", "failed to write connection to disk: %s",
 
11964
                (error && error->message) ? error->message : "(unknown)");
 
11965
 
 
11966
        ASSERT (testfile != NULL,
 
11967
                "infiniband-write", "didn't get ifcfg file path back after writing connection");
 
11968
 
 
11969
        /* re-read the connection for comparison */
 
11970
        reread = connection_from_file (testfile,
 
11971
                                       NULL,
 
11972
                                       TYPE_INFINIBAND,
 
11973
                                       NULL,
 
11974
                                       &unmanaged,
 
11975
                                       &keyfile,
 
11976
                                       &routefile,
 
11977
                                       &route6file,
 
11978
                                       &error,
 
11979
                                       &ignore_error);
 
11980
        unlink (testfile);
 
11981
 
 
11982
        ASSERT (reread != NULL,
 
11983
                "infiniband-write-reread", "failed to read %s: %s", testfile, error->message);
 
11984
 
 
11985
        ASSERT (nm_connection_verify (reread, &error),
 
11986
                "infiniband-write-reread-verify", "failed to verify %s: %s", testfile, error->message);
 
11987
 
 
11988
        ASSERT (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT) == TRUE,
 
11989
                "infiniband-write", "written and re-read connection weren't the same.");
 
11990
 
 
11991
        g_free (testfile);
 
11992
        g_free (unmanaged);
 
11993
        g_free (keyfile);
 
11994
        g_free (routefile);
 
11995
        g_free (route6file);
 
11996
        g_object_unref (connection);
 
11997
        g_object_unref (reread);
 
11998
}
 
11999
 
11777
12000
#define TEST_IFCFG_WIFI_OPEN_SSID_BAD_HEX TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-bad-hex"
11778
12001
#define TEST_IFCFG_WIFI_OPEN_SSID_LONG_QUOTED TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-long-quoted"
11779
12002
#define TEST_IFCFG_WIFI_OPEN_SSID_LONG_HEX TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-long-hex"
11856
12079
        test_read_wifi_wep_no_keys ();
11857
12080
        test_read_permissions ();
11858
12081
        test_read_wifi_wep_agent_keys ();
 
12082
        test_read_infiniband ();
11859
12083
 
11860
12084
        test_write_wired_static ();
11861
12085
        test_write_wired_static_ip6_only ();
11919
12143
        test_write_wired_ctc_dhcp ();
11920
12144
        test_write_permissions ();
11921
12145
        test_write_wifi_wep_agent_keys ();
 
12146
        test_write_infiniband ();
11922
12147
 
11923
12148
        /* iSCSI / ibft */
11924
12149
        test_read_ibft_dhcp ();