Leave if block for security group and for this test just create new one instance in other way you should verify if instance has assigned floating ip and if has release it (ip)