Home > Net >  Can I run Python app using WMI in GitLab CI if using Linux Docker image?
Can I run Python app using WMI in GitLab CI if using Linux Docker image?

Time:11-14

Objective

In Gitlab runner, run:

  1. some JMeter tests
  2. a Python application that uses WMI to collect server metrics

Problem

The JMeter commands worked fine, using the alpine/jmeter image.

default:
  image:
    name: alpine/jmeter:5.4.1
    entrypoint: [""]

No problem there.

But I want to run a Python program I wrote that uses WMI to get Windows performance counters.

Problem: when doing pip install -r requirements.txt, everything gets installed, but that last part fails:

$ pip install -r ../../requirements.txt
Collecting certifi==2021.5.30
  Downloading certifi-2021.5.30-py2.py3-none-any.whl (145 kB)
Collecting cffi==1.14.5
  Downloading cffi-1.14.5-cp38-cp38-manylinux1_x86_64.whl (411 kB)
Collecting chardet==4.0.0
  Downloading chardet-4.0.0-py2.py3-none-any.whl (178 kB)
Collecting click==8.0.1
  Downloading click-8.0.1-py3-none-any.whl (97 kB)
Collecting colorama==0.4.4
  Downloading colorama-0.4.4-py2.py3-none-any.whl (16 kB)
Collecting ConfigArgParse==1.5
  Downloading ConfigArgParse-1.5-py3-none-any.whl (19 kB)
Collecting crypto==1.4.1
  Downloading crypto-1.4.1-py2.py3-none-any.whl (18 kB)
Collecting Flask==1.1.2
  Downloading Flask-1.1.2-py2.py3-none-any.whl (94 kB)
Collecting Flask-BasicAuth==0.2.0
  Downloading Flask-BasicAuth-0.2.0.tar.gz (16 kB)
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'done'
Collecting gevent==21.1.2
  Downloading gevent-21.1.2-cp38-cp38-manylinux2010_x86_64.whl (6.3 MB)
Collecting geventhttpclient==1.4.4
  Downloading geventhttpclient-1.4.4-cp38-cp38-manylinux2010_x86_64.whl (77 kB)
Collecting greenlet==1.1.0
  Downloading greenlet-1.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (164 kB)
Collecting idna==2.10
  Downloading idna-2.10-py2.py3-none-any.whl (58 kB)
Collecting influxdb==5.3.1
  Downloading influxdb-5.3.1-py2.py3-none-any.whl (77 kB)
Collecting influxdb-client==1.17.0
  Downloading influxdb_client-1.17.0-py3-none-any.whl (450 kB)
Collecting itsdangerous==2.0.1
  Downloading itsdangerous-2.0.1-py3-none-any.whl (18 kB)
Collecting Jinja2==3.0.1
  Downloading Jinja2-3.0.1-py3-none-any.whl (133 kB)
Collecting locust==1.5.3
  Downloading locust-1.5.3-py3-none-any.whl (765 kB)
Collecting locust-influxdb-listener==0.0.5
  Downloading locust_influxdb_listener-0.0.5-py3-none-any.whl (7.6 kB)
Collecting MarkupSafe==2.0.1
  Downloading MarkupSafe-2.0.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (30 kB)
Collecting msgpack==1.0.2
  Downloading msgpack-1.0.2-cp38-cp38-manylinux1_x86_64.whl (302 kB)
Collecting multipledispatch==0.6.0
  Downloading multipledispatch-0.6.0-py3-none-any.whl (11 kB)
Collecting Naked==0.1.31
  Downloading Naked-0.1.31-py2.py3-none-any.whl (590 kB)
Collecting numpy==1.21.2
  Downloading numpy-1.21.2-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (15.8 MB)
Collecting pandas==1.3.2
  Downloading pandas-1.3.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.5 MB)
Collecting psutil==5.8.0
  Downloading psutil-5.8.0-cp38-cp38-manylinux2010_x86_64.whl (296 kB)
Collecting pycparser==2.20
  Downloading pycparser-2.20-py2.py3-none-any.whl (112 kB)
Collecting pycryptodome==3.10.1
  Downloading pycryptodome-3.10.1-cp35-abi3-manylinux2010_x86_64.whl (1.9 MB)
Collecting python-dateutil==2.8.1
  Downloading python_dateutil-2.8.1-py2.py3-none-any.whl (227 kB)
Collecting pytz==2021.1
  Downloading pytz-2021.1-py2.py3-none-any.whl (510 kB)
ERROR: Could not find a version that satisfies the requirement pywin32==300 (from versions: none)
ERROR: No matching distribution found for pywin32==300
Cleaning up file based variables
00:01
ERROR: Job failed: exit code 1

What I've Tried

  1. replace pywin32==301 with pypywin32

  2. ensured that python version is 3.8

  3. Tried using python:3.8-windowsservercore, but that doesn't even get off the ground because it conflicts with the default JMeter image which is Linux.

  4. I tried adding pywin32==300 to requirements.txt. The result then is just

    ERROR: Could not find a version that satisfies the requirement pywin32==300 (from versions: none)
    ERROR: No matching distribution found for pywin32==300
    
default:
  image:
    name: alpine/jmeter:5.4.1
    entrypoint: [""]

api test:
  image: 
    name: python:3.8
  stage: test
  script:
    - |
      git --version
      set -e
      cd ../..
    - rm -rf engine-load-tests
    - git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.company.net/qa/engine-automation/engine-load-tests.git
    - cd engine-load-tests/src/win_perf_counters/
    - PYTHONPATH=`pwd`./:$PYTHONPATH
    - python3 -m venv .venv
    - source .venv/bin/activate
    - python -V
    - pip install --upgrade pip
    - pip install -r ../../requirements.txt
    - python ./main.py ../../load_test.conf csv 

Am I trying to do something impossible?

Any idea how I can get the Python application to run?

CodePudding user response:

No, the wmi package relies on pywin32 which is only possible to use on Windows because it relies on Windows binary files (windows DLL files) which can only be run on Windows.

Therefore, you must run this Python app on Windows, not Linux.

Jmeter, however, does work on both Windows and Linux.

  • Related