Clean project/user if snaps tests are skipped
[functest.git] / functest / opnfv_tests / openstack / vgpu / vgpu.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2018 Kontron and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9
10 """vGPU testcase implementation."""
11
12 from __future__ import division
13
14 import logging
15
16 from functest.core import singlevm
17
18
19 class VGPU(singlevm.SingleVm2):
20     """OpenStack vGPU Test Case."""
21
22     __logger = logging.getLogger(__name__)
23
24     filename = ('/home/opnfv/functest/images/'
25                 'ubuntu-16.04-server-cloudimg-amd64-disk1.img')
26     flavor_ram = 4096
27     flavor_vcpus = 2
28     flavor_disk = 40
29     flavor_extra_specs = {'resources:VGPU': '1'}
30     username = 'ubuntu'
31     ssh_connect_loops = 12
32     create_server_timeout = 300
33
34     def __init__(self, **kwargs):
35         """Initialize vGPU testcase object."""
36         if "case_name" not in kwargs:
37             kwargs["case_name"] = "vgpu"
38         super(VGPU, self).__init__(**kwargs)
39
40     def execute(self):
41         """
42         Test if the vGPU exist.
43         """
44         (_, stdout, stderr) = self.ssh.exec_command('lspci')
45         lspci_output = stdout.read()
46         self.__logger.debug("output:\n%s", stdout.read())
47         self.__logger.debug("error:\n%s", stderr.read())
48         if ('VGA compatible controller: Intel' in lspci_output or
49                 'VGA compatible controller: Nvidia' in lspci_output):
50             self.__logger.info("The VM have a vGPU")
51             return 0
52         self.__logger.error("The VM haven't any vGPU")
53         return 1