Revision 77054bf5 snf-cyclades-app/synnefo/tools/burnin.py

b/snf-cyclades-app/synnefo/tools/burnin.py
48 48
import struct
49 49
import sys
50 50
import time
51
import hashlib
51 52

  
52 53
from IPy import IP
53 54
from multiprocessing import Process, Queue
......
351 352
        # The hostname must be of the form 'prefix-id'
352 353
        self.assertTrue(hostname.endswith("-%d\n" % self.serverid))
353 354

  
355

  
356
    def _file_md5(filename, block_size = 2**20):
357
        f = open(filename)
358
        md5 = hashlib.md5()
359
        while True:
360
            data = f.read(block_size)
361
            if not data:
362
                break
363
            md5.update(data)
364
            f.close()
365
    
366
        return md5.digest()
367

  
368
    
369
    def _check_file_through_ssh(self, hostip, username, pavssword, path):
370
        msg = "SSH to %s, as %s/%s" % (hostip, username, password)
371
        try:
372
            ssh = paramiko.SSHClient()
373
            ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
374
            ssh.connect(hostip, username=username, password=password)
375
        except socket.error:
376
            raise AssertionError
377
        
378
        transport.connect(username = username, password = password)
379
        remotepath = path
380
        localpath = '/tmp/'+SNF_TEST_PREFIX+'injection'
381
        sftp = paramiko.SFTPClient.from_transport(transport)
382
        sftp.get(remotepath, localpath)
383
        
384
        sftp.close()
385
        transport.close()
386

  
387
        # Check if files are the same
388
        return _file_md5(localpath) == _file_md5('test.txt')
389

  
354 390
    def _skipIf(self, condition, msg):
355 391
        if condition:
356 392
            self.skipTest(msg)
......
549 585
    def test_016_personality_is_enforced(self):
550 586
        """Test file injection for personality enforcement"""
551 587
        self._skipIf(self.is_windows, "only implemented for Linux servers")
552
        self.assertTrue(False, "test not implemented, will fail")
588
        
589

  
590
        #Create new server
591
        server = self.client.create_server(self.servername, self.flavorid,
592
                                           self.imageid, self.personality) #/path/to/file
593
        self.assertEqual(server["name"], self.servername)
594
        self.assertEqual(server["flavorRef"], self.flavorid)
595
        self.assertEqual(server["imageRef"], self.imageid)
596
        self.assertEqual(server["status"], "BUILD")
597
        
598
        #Test if is in active state
599
        servers = self.client.list_servers(detail=True)
600
        servers = filter(lambda x: x["name"] == self.servername, servers)
601
        self.assertEqual(len(servers), 1)
602

  
603
        #Test if server is building in details
604
        server = self.client.get_server_details(self.serverid)
605
        self.assertEqual(server["name"], self.servername)
606
        self.assertEqual(server["flavorRef"], self.flavorid)
607
        self.assertEqual(server["imageRef"], self.imageid)
608
        self.assertEqual(server["status"], "BUILD")
609

  
610
        #Insist on transition
611
        self._insist_on_status_transition("BUILD", "ACTIVE",
612
                                          self.build_fail, self.build_warning)
613
        
614
        #Test if file injected exists
615
        equal = self._check_file_through_ssh(self._get_ipv4(server), self.username, self.password)
616
        
617
        self.assertTrue(equal)
553 618

  
554 619
    def test_017_submit_delete_request(self):
555 620
        """Test submit request to delete server"""

Also available in: Unified diff