On Tue, 7 Jul 2015 at 10:44 'Hrvoje Ribicic' via ganeti-devel < [email protected]> wrote:
> This patch adds a few tests that make sure the state is handled > properly, using examples taken from a running cluster. > > Signed-off-by: Hrvoje Ribicic <[email protected]> > --- > Makefile.am | 1 + > test/data/xen-xl-list-4.4-crashed-instances.txt | 5 +++++ > test/py/ganeti.hypervisor.hv_xen_unittest.py | 30 > +++++++++++++++++++++++++ > 3 files changed, 36 insertions(+) > create mode 100644 test/data/xen-xl-list-4.4-crashed-instances.txt > > diff --git a/Makefile.am b/Makefile.am > index 79c964e..939f88c 100644 > --- a/Makefile.am > +++ b/Makefile.am > @@ -1698,6 +1698,7 @@ TEST_FILES = \ > test/data/vgreduce-removemissing-2.02.66-ok.txt \ > test/data/vgs-missing-pvs-2.02.02.txt \ > test/data/vgs-missing-pvs-2.02.66.txt \ > + test/data/xen-xl-list-4.4-crashed-instances.txt \ > test/data/xen-xm-info-4.0.1.txt \ > test/data/xen-xm-list-4.0.1-dom0-only.txt \ > test/data/xen-xm-list-4.0.1-four-instances.txt \ > diff --git a/test/data/xen-xl-list-4.4-crashed-instances.txt > b/test/data/xen-xl-list-4.4-crashed-instances.txt > new file mode 100644 > index 0000000..aa8ae49 > --- /dev/null > +++ b/test/data/xen-xl-list-4.4-crashed-instances.txt > @@ -0,0 +1,5 @@ > +Name ID Mem VCPUs State > Time(s) > +Domain-0 0 1023 1 r----- > 154706.1 > +server01.example.com 1 1024 1 -b---- > 167643.2 > +(null) 28441 789 1 --psc- > 1.2 > +alsodying.example.com 28448 1024 1 --psc- > 1.4 > diff --git a/test/py/ganeti.hypervisor.hv_xen_unittest.py b/test/py/ > ganeti.hypervisor.hv_xen_unittest.py > index ddb92d4..ba6324e 100755 > --- a/test/py/ganeti.hypervisor.hv_xen_unittest.py > +++ b/test/py/ganeti.hypervisor.hv_xen_unittest.py > @@ -198,6 +198,19 @@ class TestInstanceStateParsing(unittest.TestCase): > self.assertEqual(hv_xen._XenToHypervisorInstanceState(state), > hv_base.HvInstanceState.SHUTDOWN) > > + def testCrashingStates(self): > + states = [ > + "--psc-", > + "---sc-", > + "---scd", > + "--p-c-", > + "----c-", > + "----cd", > + ] > + for state in states: > + self.assertRaises(hv_xen._InstanceCrashed, > + hv_xen._XenToHypervisorInstanceState, state) > + > > class TestGetInstanceList(testutils.GanetiTestCase): > def _Fail(self): > @@ -241,6 +254,23 @@ class TestGetInstanceList(testutils.GanetiTestCase): > > self.assertEqual(fn.Count(), 1) > > + def testOmitCrashed(self): > + data = testutils.ReadTestData("xen-xl-list-4.4-crashed-instances.txt") > + > + fn = testutils.CallCounter(compat.partial(self._Success, data)) > + > + result = hv_xen._GetAllInstanceList(fn, True, delays=(0.02, 1.0, > 0.03), > + timeout=0.1) > + > + self.assertEqual(len(result), 2) > + > + self.assertEqual(map(compat.fst, result), [ > + "Domain-0", > + "server01.example.com", > + ]) > + > + self.assertEqual(fn.Count(), 1) > + > > class TestParseNodeInfo(testutils.GanetiTestCase): > def testEmpty(self): > -- > 2.4.3.573.g4eafbef > > LGTM, thanks -- Helga Velroyen Software Engineer [email protected] Google Germany GmbH Dienerstraße 12 80331 München Geschäftsführer: Graham Law, Christine Elizabeth Flores Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Diese E-Mail ist vertraulich. Wenn Sie nicht der richtige Adressat sind, leiten Sie diese bitte nicht weiter, informieren Sie den Absender und löschen Sie die E-Mail und alle Anhänge. Vielen Dank. This e-mail is confidential. If you are not the right addressee please do not forward it, please inform the sender, and please erase this e-mail including any attachments. Thanks.
