aboutsummaryrefslogtreecommitdiffstats
path: root/functest/opnfv_tests/openstack/vgpu/vgpu.py
blob: c8180a45c944155b2e101c1dc079e09ca233c1d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python

# Copyright (c) 2018 Kontron and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0

"""vGPU testcase implementation."""

from __future__ import division

import logging

from functest.core import singlevm


class VGPU(singlevm.SingleVm2):
    """OpenStack vGPU Test Case."""

    __logger = logging.getLogger(__name__)

    filename = ('/home/opnfv/functest/images/'
                'ubuntu-16.04-server-cloudimg-amd64-disk1.img')
    flavor_ram = 4096
    flavor_vcpus = 2
    flavor_disk = 40
    flavor_extra_specs = {'resources:VGPU': '1'}
    username = 'ubuntu'
    ssh_connect_loops = 12
    create_server_timeout = 300

    def __init__(self, **kwargs):
        """Initialize vGPU testcase object."""
        if "case_name" not in kwargs:
            kwargs["case_name"] = "vgpu"
        super(VGPU, self).__init__(**kwargs)

    def execute(self):
        """
        Test if the vGPU exist.
        """
        (_, stdout, stderr) = self.ssh.exec_command('lspci')
        lspci_output = stdout.read()
        self.__logger.debug("output:\n%s", stdout.read())
        self.__logger.debug("error:\n%s", stderr.read())
        if ('VGA compatible controller: Intel' in lspci_output or
                'VGA compatible controller: Nvidia' in lspci_output):
            self.__logger.info("The VM have a vGPU")
            return 0
        self.__logger.error("The VM haven't any vGPU")
        return 1