Revision 9e4682b5

b/snf-cyclades-app/synnefo/tools/burnin.py
1
#!/usr/bin/env python
1
 #!/usr/bin/env python
2 2

  
3 3
# Copyright 2011 GRNET S.A. All rights reserved.
4 4
#
......
567 567
        self.assertNotIn(self.serverid, [s["id"] for s in servers])
568 568

  
569 569

  
570
class NetworksTestCase(unittest.TestCase):
570
class NetworkTestCase(unittest.TestCase):
571 571
    """ Testing networking in cyclades """
572
    @classmethod
572 573
    def setUpClass(cls):
573 574
        "Initialize kamaki, get list of current networks"
574 575
        conf = Config()
575 576
        conf.set('compute_token', TOKEN)
576 577
        cls.client = CycladesClient(conf)
578
        cls.compute = ComputeClient(conf)
579

  
580
        images = cls.compute.list_images(detail = True)
581
        flavors = cls.compute.list_flavors(detail = True)
582
        imageid = choice([im['id'] for im in images])
583
        flavorid = choice([f["id"] for f in flavors if f["disk"] >= 20])
584

  
585
        for image in images:
586
            if image['id'] == imageid:
587
                imagename = image['name']
577 588

  
578
        #TODO: Create servers, insist until ACTIVE
579
        #cls.serverid = 
589
        servername = "%s%s for %s" % (SNF_TEST_PREFIX, TEST_RUN_ID, imagename)
590
        is_windows = imagename.lower().find("windows") >= 0
591
        setupCase =  _spawn_server_test_case(imageid=str(imageid), flavorid=flavorid,
592
                                             imagename=imagename,
593
                                             personality=None,
594
                                             servername=servername,
595
                                             is_windows=is_windows,
596
                                             action_timeout=200,
597
                                             build_warning=1200,
598
                                             build_fail=500,
599
                                             query_interval=3)
600

  
601
        #Using already implemented tests for serverlist population
602
        suite = unittest.TestSuite()
603
        suite.addTest(setupCase('test_001_submit_create_server'))
604
        suite.addTest(setupCase('test_002a_server_is_building_in_list'))
605
        suite.addTest(setupCase('test_002b_server_is_building_in_details'))        
606
        suite.addTest(setupCase('test_003_server_becomes_active'))
607
        unittest.TextTestRunner(verbosity=2).run(suite)
580 608

  
581
    def test_001_create_network():
609
    def test_001_create_network(self):
582 610
        """Test submit create network request"""
583 611
        name = SNF_TEST_PREFIX+TEST_RUN_ID
584
        network =  self.client.create_network(name)
612
        network =  self.client.create_network(name)        
613
        previous_num = len(self.client.list_networks())
614

  
615
        #Test if right name is assigned
585 616
        self.assertEqual(network['name'], name)
586 617
        
587
        # Update class attributes to reflect data on new network
618
        # Update class attributes
588 619
        cls = type(self)
589 620
        cls.networkid = network['id']
621
        networks = self.client.list_networks()
622

  
623
        #Test if new network is created
624
        self.assertTrue(len(networks) > previous_num)
625
        
590 626
    
591
    def test_002_connect_to_network():
627
    def test_002_connect_to_network(self):
592 628
        """Test VM to network connection"""
593
        self.client.connect_server(self.serverid, self.networkid)
629
        servers = self.compute.list_servers()
630
        server = choice(servers)
631
        self.client.connect_server(server['id'], self.networkid)
632
        
633
        #Update class attributes
634
        cls = type(self)
635
        cls.serverid = server['id']
636

  
637
        connected = (self.client.get_network_details(self.networkid))
638
        connections = len(connected['servers']['values'])
639
        
640
        time.sleep(60)
641

  
642
        #FIXME: Insist on new connection
643
        self.assertTrue(connections>=1)
644
        
645

  
646
    def test_003_disconnect_from_network(self):
647
        prev_state = (self.client.get_network_details(self.networkid))
648
        prev_conn = len(prev_state['servers']['values'])
594 649

  
595
    def test_003_disconnect_from_network():
596 650
        self.client.disconnect_server(self.serverid, self.networkid)
597
    
598
    def test_004_destroy_network():
651
        connected = (self.client.get_network_details(self.networkid))
652
        curr_conn = len(connected['servers']['values'])
653

  
654
        #FIXME: Insist on deleting
655
        self.assertTrue(curr_conn < prev_conn)
656

  
657
    def test_004_destroy_network(self):
599 658
        """Test submit delete network request"""
600 659
        self.client.delete_network(self.networkid)
660
        
661
        networks = self.client.list_networks()
662
        self.assertEqual(len(networks),1)
601 663

  
602
    
603
    
604 664

  
605 665
class TestRunnerProcess(Process):
606 666
    """A distinct process used to execute part of the tests in parallel"""
......
744 804
                      metavar="TIMEOUT",
745 805
                      help="Wait SECONDS seconds for a server action to " \
746 806
                           "complete, then the test is considered failed",
747
                      default=50)
807
                      default=100)
748 808
    parser.add_option("--build-warning",
749 809
                      action="store", type="int", dest="build_warning",
750 810
                      metavar="TIMEOUT",
......
866 926
        personality = None   # FIXME
867 927
        servername = "%s%s for %s" % (SNF_TEST_PREFIX, TEST_RUN_ID, imagename)
868 928
        is_windows = imagename.lower().find("windows") >= 0
929
        
869 930
        ServerTestCase = _spawn_server_test_case(imageid=imageid, flavorid=flavorid,
870
                                       imagename=imagename,
871
                                       perssonality=personality,
872
                                       servername=servername,
873
                                       is_windows=is_windows,
874
                                       action_timeout=opts.action_timeout,
875
                                       build_warning=opts.build_warning,
876
                                       build_fail=opts.build_fail,
877
                                       query_interval=opts.query_interval)
931
                                                 imagename=imagename,
932
                                                 personality=personality,
933
                                                 servername=servername,
934
                                                 is_windows=is_windows,
935
                                                 action_timeout=opts.action_timeout,
936
                                                 build_warning=opts.build_warning,
937
                                                 build_fail=opts.build_fail,
938
                                                 query_interval=opts.query_interval)
878 939

  
879 940

  
880 941
    #Running all the testcases sequentially
881
    seq_cases = [UnauthorizedTestCase, FlavorsTestCase, ImagesTestCase, ServerTestCase, NetworkTestCase]
942
    #seq_cases = [UnauthorizedTestCase, FlavorsTestCase, ImagesTestCase, ServerTestCase, NetworkTestCase]
943

  
944
    seq_cases = [NetworkTestCase]
882 945
    for case in seq_cases:
883 946
        suite = unittest.TestLoader().loadTestsFromTestCase(case)
884 947
        unittest.TextTestRunner(verbosity=2).run(suite)

Also available in: Unified diff