File: test_windows.py

package info (click to toggle)
python-moto 5.1.18-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 116,520 kB
  • sloc: python: 636,725; javascript: 181; makefile: 39; sh: 3
file content (33 lines) | stat: -rw-r--r-- 1,241 bytes parent folder | download | duplicates (2)
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
import os
from unittest import SkipTest, mock

import boto3

from moto import mock_aws, settings
from tests import EXAMPLE_AMI_PARAVIRTUAL, EXAMPLE_AMI_WINDOWS


# The default AMIs are not loaded for our test case, to speed things up
# But we do need it for this specific test (and others in this file..)
@mock.patch.dict(os.environ, {"MOTO_EC2_LOAD_DEFAULT_AMIS": "true"})
@mock_aws
def test_get_password_data():
    if settings.TEST_SERVER_MODE:
        raise SkipTest("Can't set environment variables in ServerMode")
    client = boto3.client("ec2", region_name="us-east-1")

    # Ensure non-windows instances return empty password data
    instance_id = client.run_instances(
        ImageId=EXAMPLE_AMI_PARAVIRTUAL, MinCount=1, MaxCount=1
    )["Instances"][0]["InstanceId"]
    resp = client.get_password_data(InstanceId=instance_id)
    assert resp["InstanceId"] == instance_id
    assert resp["PasswordData"] == ""

    # Ensure Windows instances
    instance_id = client.run_instances(
        ImageId=EXAMPLE_AMI_WINDOWS, MinCount=1, MaxCount=1
    )["Instances"][0]["InstanceId"]
    resp = client.get_password_data(InstanceId=instance_id)
    assert resp["InstanceId"] == instance_id
    assert len(resp["PasswordData"]) == 128