3 from robot.api import logger
4 from robot.libraries.BuiltIn import BuiltIn
5 from test_constants import *
8 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '../libraries/common'))
10 ex = BuiltIn().get_library_instance('execute_command')
11 stack_infos = BuiltIn().get_library_instance('stack_infos')
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)
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()
26 logger.info("\nchecking docker daemon settings on " + node + " : " + nodes[node])
27 ex.execute_unix_command_on_remote_as_root(command, nodes[node])
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)
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)
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")
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)
50 def delete_files_from_node(nodeIp, listOfFiles):
53 ex.execute_unix_command_on_remote_as_root(command + '/var/lib/docker/' + f, nodeIp)
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)
61 def step2_check_copy_files():
62 crfNodes = stack_infos.get_crf_nodes()
63 nodeIp = crfNodes.values()[0]
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!")
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):
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)