robot tcs, test charts, robot container added
[ta/cloudtaf.git] / testcases / basic_func_tests / tc_007_ssh_test_overlay_quota.py
1 import sys
2 import os
3 from robot.api import logger
4 from robot.libraries.BuiltIn import BuiltIn
5 from test_constants import *
6 import common_utils
7
8 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '../libraries/common'))
9
10 ex = BuiltIn().get_library_instance('execute_command')
11 stack_infos = BuiltIn().get_library_instance('stack_infos')
12
13
14 def tc_007_ssh_test_overlay_quota():
15     steps = ['step1_check_storage_driver_and_quota_setting',
16              'step2_check_copy_files']
17     common_utils.keyword_runner(steps)
18
19
20 def step1_check_storage_driver_and_quota_setting():
21     logger.info("step1: check size of all container")
22     command = r"ps -eaf | grep --color=no dockerd | grep --color=no " \
23               r"'\-\-storage-driver overlay2 \-\-storage-opt overlay2.size='" + docker_size_quota
24     nodes = stack_infos.get_all_nodes()
25     for node in nodes:
26         logger.info("\nchecking docker daemon settings on " + node + " : " + nodes[node])
27         ex.execute_unix_command_on_remote_as_root(command, nodes[node])
28
29
30 def get_containerid_of_flannel_from_node(nodeIp):
31     return ex.execute_unix_command_on_remote_as_root("docker ps | grep flanneld | cut -d ' ' -f1", nodeIp)
32
33
34 def allocate_file_on_node(nodeIp, size, test_file):
35     command = "fallocate -l " + size + " /var/lib/docker/" + test_file
36     return ex.execute_unix_command_on_remote_as_root(command, nodeIp)
37
38
39 def copy_file_to_container(nodeIp, containerId, actual_file):
40     command = "docker cp " + actual_file + " " + containerId + ":/"
41     return ex.execute_unix_command_on_remote_as_root(command, nodeIp, delay="120s")
42
43
44 def delete_files_from_container(nodeIp, containerId, listOfFiles):
45     command = "docker exec -ti " + containerId + " rm -f /"
46     for file in listOfFiles:
47         ex.execute_unix_command_on_remote_as_root(command + file, nodeIp)
48
49
50 def delete_files_from_node(nodeIp, listOfFiles):
51     command = "rm -f "
52     for f in listOfFiles:
53         ex.execute_unix_command_on_remote_as_root(command + '/var/lib/docker/' + f, nodeIp)
54
55
56 def test_copy_file(nodeIp, fileSize, fileName, containerId):
57     allocate_file_on_node(nodeIp, fileSize, fileName)
58     copy_file_to_container(nodeIp, containerId, "/var/lib/docker/" + fileName)
59
60
61 def step2_check_copy_files():
62     crfNodes = stack_infos.get_crf_nodes()
63     nodeIp = crfNodes.values()[0]
64     if not nodeIp:
65         raise Exception("controller-1 internal ip address is not available!")
66     containerId = get_containerid_of_flannel_from_node(nodeIp)
67     listOfFiles = ["tmp_file", "tiny_file"]
68     file_size = str(int(docker_size_quota[:-1]) * 1024 - 5) + 'M'
69     logger.info("step2: copy a smaller file than overlay quota to flannel.")
70     test_copy_file(nodeIp, file_size, listOfFiles[0], containerId)
71     logger.info("step2: copy 10 Mbytes file to flannel container. It should fail!")
72     try:
73         test_copy_file(nodeIp, "10M", listOfFiles[1], containerId)
74     except Exception as e:
75         if "no space left on device" not in str(e):
76             raise e
77         logger.info("file can't be copied to container as expected")
78     delete_files_from_container(nodeIp, containerId, listOfFiles)
79     delete_files_from_node(nodeIp, listOfFiles)