summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBen Howard <ben.howard@ubuntu.com>2015-03-25 11:04:05 -0600
committerusd-importer <ubuntu-server@lists.ubuntu.com>2015-04-10 23:48:27 +0000
commitc40af8b3fec1b840776ca36d64b1857ed2bdd95b (patch)
tree1a3a285788176bf6cb7d7ab3a5cf757011fcfb9f /tests
parentf9cd6b27fad4d9fdf557138966f2d34cae234edb (diff)
downloadvyos-walinuxagent-c40af8b3fec1b840776ca36d64b1857ed2bdd95b.tar.gz
vyos-walinuxagent-c40af8b3fec1b840776ca36d64b1857ed2bdd95b.zip
Import patches-unapplied version 2.0.12-0ubuntu1 to ubuntu/vivid-proposed
Imported using git-ubuntu import. Changelog parent: f9cd6b27fad4d9fdf557138966f2d34cae234edb New changelog entries: * New upstream release. * Added debian/watch for easier maintenance. * Fix regression of missing dataloss warning by adding systemd unit file.
Diffstat (limited to 'tests')
-rw-r--r--tests/env.py2
-rw-r--r--tests/part-gpt.py31
-rw-r--r--tests/test_logger.py35
-rw-r--r--tests/test_shared_config.py85
-rw-r--r--tests/upload_status_blob.py37
5 files changed, 189 insertions, 1 deletions
diff --git a/tests/env.py b/tests/env.py
index ea33c89..4e9e052 100644
--- a/tests/env.py
+++ b/tests/env.py
@@ -19,5 +19,5 @@ import os
projet_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
waagent = imp.load_source('waagent', os.path.join(projet_root, 'waagent'))
-waagent.LoggerInit('/tmp/test.log','/dev/stdout')
+waagent.LoggerInit('/dev/stdout', '/dev/null')
diff --git a/tests/part-gpt.py b/tests/part-gpt.py
new file mode 100644
index 0000000..373e1c6
--- /dev/null
+++ b/tests/part-gpt.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+#
+# Copyright 2014 Microsoft Corporation
+#
+# 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.
+#
+# Implements parts of RFC 2131, 1541, 1497 and
+# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
+# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
+#
+
+import subprocess
+
+if __name__ == '__main__':
+ subprocess.call(['umount', '/mnt/resource'])
+ subprocess.call(['umount', '/mnt'])
+ subprocess.call(['parted', '/dev/sdb', 'print'])
+ subprocess.call(['parted', '/dev/sdb', 'rm', '1'])
+ subprocess.call(['parted', '/dev/sdb', 'mklabel', 'gpt'])
+ subprocess.call(['parted', '/dev/sdb', 'mkpart', 'primary', '0%', '50%'])
+ subprocess.call(['parted', '/dev/sdb', 'mkpart', 'primary', '50%', '100%'])
diff --git a/tests/test_logger.py b/tests/test_logger.py
new file mode 100644
index 0000000..d188277
--- /dev/null
+++ b/tests/test_logger.py
@@ -0,0 +1,35 @@
+# Copyright 2014 Microsoft Corporation
+#
+# 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 unittest
+from env import waagent
+
+
+class TestWAAgentLogger(unittest.TestCase):
+
+ def test_log_to_non_exists_dev(self):
+ logger = waagent.Logger('/tmp/testlog', '/dev/nonexists')
+ logger.Log("something")
+
+ def test_log_to_non_exists_file(self):
+ logger = waagent.Logger('/tmp/nonexists/testlog', '/tmp/testconsole')
+ logger.Log("something")
+
+ def test_log_unicode(self):
+ logger = waagent.Logger('/tmp/testlog', '/tmp/testconsole')
+ logger.Log(u"anything\u6211\u7231\u5201\u831C".encode("utf-8"))
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tests/test_shared_config.py b/tests/test_shared_config.py
new file mode 100644
index 0000000..75220b8
--- /dev/null
+++ b/tests/test_shared_config.py
@@ -0,0 +1,85 @@
+# Copyright 2014 Microsoft Corporation
+#
+# 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 unittest
+from env import waagent
+
+
+class TestSharedConfig(unittest.TestCase):
+
+ def test_parse_shared_config(self):
+ conf = waagent.SharedConfig().Parse(SharedConfigText)
+ self.assertNotEquals(None, conf)
+ self.assertNotEquals(None, conf.RdmaMacAddress)
+ self.assertNotEquals(None, conf.RdmaIPv4Address)
+ return conf
+
+ def test_config_rdma(self):
+ waagent.LoggerInit("/dev/stdout", "/dev/null", verbose=True)
+ testDev = "/tmp/hvnd_rdma"
+ waagent.SetFileContents(testDev, "")
+ conf = self.test_parse_shared_config()
+ conf.ConfigRdma(dev=testDev)
+ rdmaConf = waagent.GetFileContents(testDev)
+ self.assertNotEquals(None, rdmaConf)
+ self.assertNotEquals("", rdmaConf)
+
+SharedConfigText="""\
+<?xml version="1.0" encoding="utf-8"?>
+<SharedConfig version="1.0.0.0" goalStateIncarnation="1">
+ <Deployment name="698f959e434c41cc9d72a2c67c044463" guid="{ba92e945-0302-4030-9710-257c03c07e22}" incarnation="0" isNonCancellableTopologyChangeEnabled="false">
+ <Service name="test-rdms" guid="{00000000-0000-0000-0000-000000000000}" />
+ <ServiceInstance name="698f959e434c41cc9d72a2c67c044463.0" guid="{6f157bcb-b6ac-4fdd-9789-2ca466220e17}" />
+ </Deployment>
+ <Incarnation number="1" instance="test-rdms" guid="{33d19bb6-f34d-4dfb-966c-2bade1714cc5}" />
+ <Role guid="{dad0becc-5d1d-3c55-3285-0136e9933bbe}" name="test-rdms" settleTimeSeconds="0" />
+ <LoadBalancerSettings timeoutSeconds="0" waitLoadBalancerProbeCount="8">
+ <Probes>
+ <Probe name="D41D8CD98F00B204E9800998ECF8427E" />
+ <Probe name="423A4BBA20CEBE79BA641B20A03ED6F9" />
+ </Probes>
+ </LoadBalancerSettings>
+ <OutputEndpoints>
+ <Endpoint name="test-rdms:openInternalEndpoint" type="SFS">
+ <Target instance="test-rdms" endpoint="openInternalEndpoint" />
+ </Endpoint>
+ </OutputEndpoints>
+ <Instances>
+ <Instance id="test-rdms" address="100.74.58.20" primaryMacAddress="000D3A101ED4" rdmaMacAddress="00155D340044" rdmaIPv4Address="172.16.2.59">
+ <FaultDomains randomId="0" updateId="0" updateCount="0" />
+ <InputEndpoints>
+ <Endpoint name="openInternalEndpoint" address="100.74.58.20" protocol="any" isPublic="false" enableDirectServerReturn="false" isDirectAddress="false" disableStealthMode="false">
+ <LocalPorts>
+ <LocalPortSelfManaged />
+ </LocalPorts>
+ </Endpoint>
+ <Endpoint name="SSH" address="100.74.58.20:22" protocol="tcp" hostName="test-rdmsContractContract" isPublic="true" loadBalancedPublicAddress="104.45.128.35:22" enableDirectServerReturn="false" isDirectAddress="false" disableStealthMode="false">
+ <LocalPorts>
+ <LocalPortRange from="22" to="22" />
+ </LocalPorts>
+ </Endpoint>
+ <Endpoint name="test-rdms_A9_Infiniband" address="100.74.58.20" protocol="any" isPublic="false" enableDirectServerReturn="false" isDirectAddress="false" disableStealthMode="false">
+ <LocalPorts>
+ <LocalPortSelfManaged />
+ </LocalPorts>
+ </Endpoint>
+ </InputEndpoints>
+ </Instance>
+ </Instances>
+</SharedConfig>
+"""
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tests/upload_status_blob.py b/tests/upload_status_blob.py
new file mode 100644
index 0000000..af8c580
--- /dev/null
+++ b/tests/upload_status_blob.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+#
+# Copyright 2014 Microsoft Corporation
+#
+# 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.
+#
+# Implements parts of RFC 2131, 1541, 1497 and
+# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
+# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
+#
+
+import os
+from env import waagent
+"""
+To run the test, you need to create a file under the same directory called:
+ status_blob_url.py
+and defined the following 2 variables like:
+ blockBlobUrl="<sas link to a block blob with w/r access>"
+ pageBlobUrl="<sas link to a page blob with w/r access>"
+"""
+from status_blob_url import blockBlobUrl, pageBlobUrl
+
+if __name__ == '__main__':
+ waagent.LoggerInit('/dev/stdout', '/dev/null', verbose=True)
+ status = "a" * 512
+ waagent.UploadStatusBlob(blockBlobUrl, status.encode("utf-8"))
+ waagent.UploadStatusBlob(pageBlobUrl, status.encode("utf-8"))