def test_failover_standby(self):
     
     master = fake()
     master.instance_id = "master_instance_id"
     master.id = "master_id"
     when(InstanceGroupItem).get_by_gid_type(any(), any(),any()).thenReturn([master])
     
     when(InstanceGroupItem).update_type(context=any(), 
               item_id=any(), 
               type=any()).thenReturn(None)
     group_item = fake()
     group_item.group_id = 1
     group_item.id = 1
     when(InstanceGroupItem).get_by_instance_id(any(),any()).thenReturn(group_item)
     
     when(FreshInstanceTasks)._relocate_master(master_id=any(), slave_id=any()).thenReturn(None)
     pass
     old_group_item = fake()
     old_group_item.instance_id = "old_instance_id"
     old_group_item.group_id = "old_group_id"
     old_group_item.id = "old_group_item_id"
     self.instance._failover_standby(old_group_item)
     
     verify(InstanceGroupItem,times=2).update_type(context=any(), 
               item_id=any(), 
               type=any())
     verify(FreshInstanceTasks,times=1)._relocate_master(master_id=any(), slave_id=any())
 def test_upgrade_instance_toha(self):
     flavor = "flavor"
     image_id = "image_id"
     databases = "databases"
     users = "users"
     service_type = "service_type"
     volume_size = "volume_size"
     security_groups = "security_groups"
     backup_id = "backup_id"
     master_id = "master_id"
 
     
     when(models.Instance).get_pyhhostname(any(),any()).thenReturn("master_phyhost")
     when(FreshInstanceTasks).create_instance(any(), any(), any(), any(),
                     any(), any(), any(),
                     any(), any(), ignore_hosts=any(),
                     master_id=any()).thenReturn(None)
     self.instance.upgrade_instance_toha(flavor, image_id, databases, users,
                     service_type, volume_size, security_groups, master_id,
                     backup_id)
     
     verify(models.Instance).get_pyhhostname(any(), any())
     verify(FreshInstanceTasks).create_instance(any(), any(), any(), any(),
                     any(), any(), any(),
                     any(), any(), ignore_hosts=any(),
                     master_id=any())
예제 #3
0
 def test_allocate_vip_with_vip_address(self):
     instance_id = "instance-id"
     vip_address = "vip_address"
     
     instance = fake()
     server =fake()
     server.networks = {"private": [ "10.1.0.13"] }
     instance.server =  server
     when(BuiltInstance).load(any(), any()).thenReturn(instance)
     
     when(instance_vip).create_member(any(),any(),any(),any(),any()).thenReturn('member_id')
     
     vip = fake()
     vip.id = "vip_id"
     vip.lb_id = "lb_id"
     when(models.DBVips).find_by(any(),vip=any(),deleted=any()).thenReturn(vip)
     
     when(models.DBInstanceVip).create(instance_id=any(),rip=any(),rport=any(),vip_id=any(),mid=any()).thenReturn(None)
     
     vip_1= vip_service.allocate(self.context,instance_id,vip_address=vip_address)
     self.assertEqual(vip_address,vip_1)
     
     verify(instance_vip,times=0).create_pool(any(),any())
     verify(instance_vip,times=0).create_vip(any(),any(),any(),any())
     verify(models.DBVips,times=0).create(vip=any(),vport=any(),lb_id =any())
     verify(instance_vip).create_member(any(),any(),any(),any(),any())
     verify(models.DBVips).find_by(any(),vip=any(),deleted=any())
 def test_create_instance_standby(self):
     instance_type = InstanceType.STANDBY
     self._create_instance(instance_type)
     verify(task_api.API).upgrade_instance_toha(any(), any(), any(),
                                               any(), any(), any(),
                                               any(), any(),
                                               any(), any(), 
                                               any())
 def test_check_backup_BackupNotCompleteError(self):
     backup = fake()
     backup.location="/exist/path/backup"
     backup.is_running = True
     when(Backup).get_by_id(any(),any()).thenReturn(backup)
     self.assertRaises(exception.BackupNotCompleteError,models.Instance._check_backup,self.context,"backup_id")
     verify(Backup).get_by_id(any(),any())
     verify(Backup,times=0).check_object_exist(any(),any())
 def test_create_instance_rr(self):
     instance_type = InstanceType.RR
     self._create_instance(instance_type)
     verify(task_api.API).create_rr_instance(any(), any(), any(),
                                               any(), any(), any(),
                                               any(), any(),
                                               any(), any(), 
                                               any())
 def test_create_instance_sg(self):
     instance_type = InstanceType.SG
     self._create_instance(instance_type)
     verify(task_api.API).create_sg_instance(any(), any(), 
                                               any(),any(), 
                                               any(),any(),any(),any(),
                                               any(),any(),
                                               any())
     pass
 def test_create_instance_ha(self):
     instance_type = InstanceType.HA
     self._create_instance(instance_type)
     verify(task_api.API,times=1).create_ha_instance(any(), any(), 
                                               any(),any(), 
                                               any(),any(),any(),any(),
                                               any(),any(),
                                               any(),any(),any())
     pass
 def test_create_security_group_RR(self):
     instance_type = InstanceType.RR
     self._create_security_group(instance_type)
     verify(SecurityGroup,times=0).create_for_instance(any(),any())
     verify(SecurityGroupRule,times=0).create_sec_group_rule(any(),
                         any(),
                         any(),
                         any(),
                         any(),
                         any())
 def test_check_backup_BackupFileNotFound(self):
     backup = fake()
     backup.is_running = False
     backup.location="/exist/path/backup"
     when(Backup).get_by_id(any(),any()).thenReturn(backup)
     when(Backup).check_object_exist(any(),any()).thenReturn(False)
     self.assertRaises(exception.BackupFileNotFound,models.Instance._check_backup,self.context,"backup_id")
     
     verify(Backup,times=1).get_by_id(any(),any())
     verify(Backup,times=1).check_object_exist(any(),any())
 def test_failover_rr(self):
     
     master = fake()
     master.instance_id = "master_instance_id"
     master.id = "master_id"
     when(InstanceGroupItem).get_by_gid_type(any(), any(),any()).thenReturn([master])
     
     when(InstanceGroupItem).update_type(context=any(), 
               item_id=any(), 
               type=any()).thenReturn(None)
     group_item = fake()
     group_item.group_id = 1
     group_item.id = 1
     when(InstanceGroupItem).get_by_instance_id(any(),any()).thenReturn(group_item)
     
     when(FreshInstanceTasks)._relocate_master(master_id=any(), slave_id=any()).thenReturn(None)
     
     CONF.trove_vip_support = True
     when(InstanceVip).get_by_instance_id(any(),any()).thenReturn("localhost")
     when(InstanceVip).allocate(any(),instance_id=any(),vip=any()).thenReturn("localhost")
     
     
     pass
     old_group_item = fake()
     old_group_item.instance_id = "old_instance_id"
     old_group_item.group_id = "old_group_id"
     old_group_item.id = "old_group_item_id"
     self.instance._failover_rr(old_group_item)
     
     verify(InstanceGroupItem,times=2).update_type(context=any(), 
               item_id=any(), 
               type=any())
     verify(FreshInstanceTasks,times=1)._relocate_master(master_id=any(), slave_id=any())
     verify(InstanceVip).get_by_instance_id(any(),any())
     verify(InstanceVip).allocate(any(),instance_id=any(),vip=any())
 def test_create_rr(self):
     name = "NAME"
     flavor_id = "flavor_id"
     image_id = "image_id"
     databases = "databases"
     users = "users"
     service_type = "mysql"
     volume_size = "10"
     backup_id = "backup_id"
     master_id = "master_id"
     extend = ""
     
     when(KSC_Instance)._create_instance(any(), any(), 
                              any(), any(), any(), any(), 
                              any(), any(), any(), any(), any(), any()).thenReturn(None)
                              
     
     instance_type = InstanceType.RR
     group_item = fake()
     group_item.id = 1     
     group_item.type = DBInstanceType.MASTER
     when(InstanceGroupItem).get_by_instance_id(any(), any()).thenReturn(group_item)
                                                   
                                                   
     when(KSC_Instance).is_service_active(any(), instance_id=any()).thenReturn(None)
     when(KSC_Instance).is_lastbackup_ready(any(), instance_id=any()).thenReturn(None)
     self.assertEqual(None,KSC_Instance.create(self.context, name, flavor_id,
                                                image_id, databases, users, service_type, 
                                                volume_size, backup_id,instance_type,extend,master_id))
     
     verify(InstanceGroupItem).get_by_instance_id(any(), any())
     
     group_item.type = DBInstanceType.STANDBY
     self.assertRaises(Exception,KSC_Instance.create,self.context, name, flavor_id,
                                                image_id, databases, users, service_type, 
                                                volume_size, backup_id,instance_type,extend,master_id)
     
     
     when(KSC_Instance).is_service_active(any(), instance_id=any()).thenRaise(Exception("is_service_active"))
     group_item.type = DBInstanceType.MASTER
     self.assertRaises(Exception,KSC_Instance.create,self.context, name, flavor_id,
                                                image_id, databases, users, service_type, 
                                                volume_size, backup_id,instance_type,extend,master_id)
 def test_delete(self):
     dbinst = models.DBInstance(InstanceTasks.NONE,name = 'name',
                                created ='created',
                                compute_instance_id = 'compute_instance_id',
                                task_id = 'task_id',
                                 task_description = 'task_description',
                                 task_start_time = 'task_start_time',
                                 volume_id = 'volume_id',
                                 deleted = 'deleted',
                                 tenant_id = 'tenant_id',
                                 service_type = 'service_type')
     server = fake()
     service_status = fake()
     service_status.status = ServiceStatuses.RUNNING
     inst = models.BaseInstance(self.context,dbinst,server,service_status)
     when(models).load_instance(any(), any(), any(), needs_server=any()).thenReturn(inst)
     
     group_item = fake()
     group_item.type = DBInstanceType.MASTER
     group_item.group_id = "group_id"
     when(InstanceGroupItem).get_by_instance_id(any(),any()).thenReturn(group_item)
     
     when(Backup).running(any()).thenReturn(False)
     when(models.BaseInstance).update_db(task_status=any()).thenReturn(None)
     when(task_api.API).delete_instance(any()).thenReturn(None)
     
     standby = fake()
     standby.instance_id = "instance_id"
     when(InstanceGroupItem).get_by_gid_type(any(), any(),any()).thenReturn(standby)
     
     standby_dbinfo = fake()
     def save():
         pass
     standby_dbinfo.save = save
     when(models.DBInstance).find_by(id=any(), deleted=any()).thenReturn(standby_dbinfo)
     
     instance = models.load_any_instance(self.context, "id")
     instance.delete()
     
     verify(InstanceGroupItem).get_by_gid_type(any(), any(),any())
     verify(models.DBInstance,times=1).find_by(id=any(), deleted=any())
 def ttest_create_server(self):
     CONF.nova_scheduler_ignore = True
     server = fake()
     server.id = 1
      
     when(os.path).isfile(any()).thenReturn(False)
     when(os.path).join(any(),any()).thenReturn(None)
     when(servers.ServerManager).create(any(), any(), any(), files=any(), userdata=any(),
         security_groups=any(), block_device_mapping=any(), 
         availability_zone=any()).thenReturn(server)
      
     flavor_id = "flavor_id"
     image_id = "image_id"
     security_groups = "security_groups"
     service_type = "service_type"
     ignore_hosts=None
     block_device_mapping = None
      
      
      
     self.assertEqual(server,self.instance._create_server(flavor_id, image_id, security_groups,
                                      service_type, block_device_mapping, ignore_hosts))
      
     verify(os.path,times=2).isfile(any())
 def test_create_security_group_HA(self):
     instance_type = InstanceType.HA
     self._create_security_group(instance_type)
     verify(SecurityGroup).create_for_instance(any(),any())
     verify(SecurityGroupRule).create_sec_group_rule(any(),
                         any(),
                         any(),
                         any(),
                         any(),
                         any())
     verify(SecurityGroup,times=0).get_security_group_by_id_or_instance_id(any(), any())
 def test_create_instance_RR(self):
     self._create_instance(DBInstanceType.READ_REPLI)
     verify(FreshInstanceTasks)._guest_prepare(any(), any(), any(),
                             any(), any(), any(),any())
     verify(FreshInstanceTasks,times=1)._update_instance_type(any(),any())
     verify(FreshInstanceTasks,times=1)._relocate_master(master_id=any(), slave_id=any())
 def test_failover_master(self):
     
     
     standby = fake()
     standby.instance_id = "standby_instance_id"
     standby.id = "standby_id"
     when(InstanceGroupItem).get_by_gid_type(any(), any(),any()).thenReturn([standby])
     
     rr = fake()
     rr.instance_id = "item_instance_id"
     rr.id = "item_id"
     
     item2 = fake()
     item2.instance_id = "item_instance_id2"
     item2.id = "item_id2"
     when(InstanceGroupItem).list_by_gid(any(), any(), is_active=any()).thenReturn([rr,standby])
     
     
     inst = fake()
     inst.guest = KSC_API(self.context,"id")
     when(models.Instance).load(any(),any()).thenReturn(inst)
     
     statusDict = {'master_server_id':'1','relay_master_log_file':'relay_master_log_file','exec_master_log_pos':1}
     when(KSC_API).ksc_show_slave_status().thenReturn(statusDict)
     
     when(KSC_API).ksc_gen_sqlfile_by_relaylog(slavestatus=any(),group_id=any(), 
                                                                      instance_id=any()).thenReturn(None)
                                                                      
     when(KSC_API).ksc_apply_sql(any(),any()).thenReturn(None)
     
     when(InstanceGroupItem).update_type(context=any(), 
               item_id=any(), 
               type=any()).thenReturn(None)
               
     when(FreshInstanceTasks)._update_instance_type(any(), instance_type=any()).thenReturn(None)
     
     when(FreshInstanceTasks)._relocate_master(master_id=any(), slave_id=any()).thenReturn(None)
     
     master_db_info = fake()
     master_db_info.name = "name"
     def save():
         pass
     master_db_info.save = save
     master_db_info.compute_instance_id = "compute_instance_id"
     when(models).get_db_info(any(), any()).thenReturn(master_db_info)
     
     new_master_server = fake()
     new_master_server.update = lambda x:x
     when(models).load_server(any(), any(), any()).thenReturn(new_master_server)
     
     CONF.trove_vip_support = True
     
     when(InstanceVip).get_by_instance_id(any(),any()).thenReturn("localhost")
     when(InstanceVip).allocate(any(),instance_id=any(),vip=any()).thenReturn("localhost")
     
     
     
     old_group_item = fake()
     old_group_item.instance_id = "old_instance_id"
     old_group_item.group_id = "group_id"
     old_group_item.id = "old_group_item_id"
     self.instance._failover_master(old_group_item)
     
     verify(KSC_API,times=2).ksc_show_slave_status()
     
     verify(KSC_API).ksc_gen_sqlfile_by_relaylog(slavestatus=any(),group_id=any(), 
                                                                      instance_id=any())
     
     verify(KSC_API).ksc_apply_sql(any(),any())
     
     verify(FreshInstanceTasks,times=2)._update_instance_type(any(), instance_type=any())
     verify(FreshInstanceTasks,times=1)._relocate_master(master_id=any(), slave_id=any())
     
     verify(InstanceVip).get_by_instance_id(any(),any())
     verify(InstanceVip).allocate(any(),instance_id=any(),vip=any())
 def test_create_instance_MASTER(self):
     self._create_instance(DBInstanceType.MASTER)
     verify(FreshInstanceTasks)._create_master_user(instance_id=any(), password=any())
     verify(FreshInstanceTasks,times=1)._update_instance_type(any(),any())