This repository has been archived by the owner on Nov 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from kumary/dev
124371356 : Created Dev branch and copied memcached code from private…
- Loading branch information
Showing
9 changed files
with
619 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# terraform-google-memcached | ||
|
||
This is a module to bring up a memcached . | ||
|
||
## Inputs | ||
|
||
|
||
## Verify | ||
|
||
### On your instance type below command : | ||
### ps -eaf | grep memcached | ||
### and it should give below output : | ||
/usr/bin/memcached -u memcached -p 11211 -m 2048 -c 1024 -t 4 -v >> /data1/applogs/memcached/memcached.log 2>&1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Copyright 2018 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
provider "google" { | ||
credentials = "${file("credentials.json")}" | ||
version = "~> 1.19" | ||
} | ||
|
||
provider "google-beta" { | ||
credentials = "${file("credentials.json")}" | ||
version = "~> 1.19" | ||
} | ||
|
||
resource "random_string" "suffix" { | ||
length = 5 | ||
special = false | ||
upper = false | ||
} | ||
|
||
module "memcached-instances" { | ||
source = "../../../" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright 2018 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/* | ||
output "instances" { | ||
description = "List of self_links for compute instances" | ||
value = ["${google_compute_instance.memcached.*.self_link}"] | ||
} | ||
output "instance_names" { | ||
description = "List of self_links for compute instances" | ||
value = ["${google_compute_instance.memcached.*.name}"] | ||
}*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright 2018 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
#project_id = attribute('project_id') | ||
#service_account_email = attribute('service_account_email') | ||
#credentials_path = attribute('credentials_path') | ||
# | ||
#ENV['CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE'] = File.absolute_path( | ||
# credentials_path, | ||
# File.join(__dir__, "../../../fixtures/minimal")) | ||
|
||
control 'memcached-instance-minimal' do | ||
title 'memcached instance minimal configuration' | ||
|
||
describe command("gcloud compute instances describe gusw1-dev-memcached-0001-001 --zone us-west1-a") do | ||
its('stdout') {should match (/status: RUNNING/)} | ||
end | ||
describe command("gcloud compute instances describe gusw1-dev-memcached-0001-002 --zone us-west1-a") do | ||
its('stdout') {should match (/status: RUNNING/)} | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
name: default |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Copyright 2018 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# This function checks to make sure that every | ||
# shebang has a '- e' flag, which causes it | ||
# to exit on error | ||
function check_bash() { | ||
find . -name "*.sh" | while IFS= read -d '' -r file; | ||
do | ||
if [[ "$file" != *"bash -e"* ]]; | ||
then | ||
echo "$file is missing shebang with -e"; | ||
exit 1; | ||
fi; | ||
done; | ||
} | ||
|
||
# This function makes sure that the required files for | ||
# releasing to OSS are present | ||
function basefiles() { | ||
echo "Checking for required files" | ||
test -f LICENSE || echo "Missing LICENSE" | ||
test -f README.md || echo "Missing README.md" | ||
} | ||
|
||
# This function runs the hadolint linter on | ||
# every file named 'Dockerfile' | ||
function docker() { | ||
echo "Running hadolint on Dockerfiles" | ||
find . -name "Dockerfile" -exec hadolint {} \; | ||
} | ||
|
||
# This function runs 'terraform validate' against all | ||
# files ending in '.tf' | ||
function check_terraform() { | ||
echo "Running terraform validate" | ||
#shellcheck disable=SC2156 | ||
find . -name "*.tf" -not -path "./**/.terraform/*" -not -path "./test/fixtures/shared/*" -exec bash -c 'terraform validate --check-variables=false $(dirname "{}")' \; | ||
} | ||
|
||
# This function runs 'go fmt' and 'go vet' on eery file | ||
# that ends in '.go' | ||
function golang() { | ||
echo "Running go fmt and go vet" | ||
find . -name "*.go" -exec go fmt {} \; | ||
find . -name "*.go" -exec go vet {} \; | ||
} | ||
|
||
# This function runs the flake8 linter on every file | ||
# ending in '.py' | ||
function check_python() { | ||
echo "Running flake8" | ||
find . -name "*.py" -exec flake8 {} \; | ||
} | ||
|
||
# This function runs the shellcheck linter on every | ||
# file ending in '.sh' | ||
function check_shell() { | ||
echo "Running shellcheck" | ||
find . -name "*.sh" -exec shellcheck -x {} \; | ||
} | ||
|
||
# This function makes sure that there is no trailing whitespace | ||
# in any files in the project. | ||
# There are some exclusions | ||
function check_trailing_whitespace() { | ||
echo "The following lines have trailing whitespace" | ||
grep -r '[[:blank:]]$' --exclude-dir=".terraform" --exclude="*.png" --exclude="*.pyc" --exclude-dir=".git" . | ||
rc=$? | ||
if [ $rc = 0 ]; then | ||
exit 1 | ||
fi | ||
} | ||
|
||
#function generate_docs() { | ||
# echo "Generating markdown docs with terraform-docs" | ||
#TMPFILE=$(mktemp) | ||
#for j in $(for i in $(find . -type f | grep \.tf$) ; do dirname "$i" ; done | sort -u) ; do | ||
# terraform-docs markdown "$j" > "$TMPFILE" | ||
#python helpers/combine_docfiles.py "$j"/README.md "$TMPFILE" | ||
#done | ||
#rm -f "$TMPFILE" | ||
#} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright 2018 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
''' A simple test for the verify_boilerplate python script. | ||
This will create a set of test files, both valid and invalid, | ||
and confirm that the has_valid_header call returns the correct | ||
value. | ||
It also checks the number of files that are found by the | ||
get_files call. | ||
''' | ||
from copy import deepcopy | ||
from tempfile import mkdtemp | ||
from shutil import rmtree | ||
import unittest | ||
from verify_boilerplate import has_valid_header, get_refs, get_regexs, \ | ||
get_args, get_files | ||
|
||
|
||
class AllTestCase(unittest.TestCase): | ||
""" | ||
All of the setup, teardown, and tests are contained in this | ||
class. | ||
""" | ||
|
||
def write_file(self, filename, content, expected): | ||
""" | ||
A utility method that creates test files, and adds them to | ||
the cases that will be tested. | ||
Args: | ||
filename: (string) the file name (path) to be created. | ||
content: (list of strings) the contents of the file. | ||
expected: (boolean) True if the header is expected to be valid, | ||
false if not. | ||
""" | ||
|
||
file = open(filename, 'w+') | ||
for line in content: | ||
file.write(line + "\n") | ||
file.close() | ||
self.cases[filename] = expected | ||
|
||
def create_test_files(self, tmp_path, extension, header): | ||
""" | ||
Creates 2 test files for .tf, .xml, .go, etc and one for | ||
Dockerfile, and Makefile. | ||
The reason for the difference is that Makefile and Dockerfile | ||
don't have an extension. These would be substantially more | ||
difficult to create negative test cases, unless the files | ||
were written, deleted, and re-written. | ||
Args: | ||
tmp_path: (string) the path in which to create the files | ||
extension: (string) the file extension | ||
header: (list of strings) the header/boilerplate content | ||
""" | ||
|
||
content = "\n...blah \ncould be code or could be garbage\n" | ||
special_cases = ["Dockerfile", "Makefile"] | ||
header_template = deepcopy(header) | ||
valid_filename = tmp_path + extension | ||
valid_content = header_template.append(content) | ||
if extension not in special_cases: | ||
# Invalid test cases for non-*file files (.tf|.py|.sh|.yaml|.xml..) | ||
invalid_header = [] | ||
for line in header_template: | ||
if "2018" in line: | ||
invalid_header.append(line.replace('2018', 'YEAR')) | ||
else: | ||
invalid_header.append(line) | ||
invalid_header.append(content) | ||
invalid_content = invalid_header | ||
invalid_filename = tmp_path + "invalid." + extension | ||
self.write_file(invalid_filename, invalid_content, False) | ||
valid_filename = tmp_path + "testfile." + extension | ||
|
||
valid_content = header_template | ||
self.write_file(valid_filename, valid_content, True) | ||
|
||
def setUp(self): | ||
""" | ||
Set initial counts and values, and initializes the setup of the | ||
test files. | ||
""" | ||
self.cases = {} | ||
self.tmp_path = mkdtemp() + "/" | ||
self.my_args = get_args() | ||
self.my_refs = get_refs(self.my_args) | ||
self.my_regex = get_regexs() | ||
self.prexisting_file_count = len( | ||
get_files(self.my_refs.keys(), self.my_args)) | ||
for key in self.my_refs: | ||
self.create_test_files(self.tmp_path, key, | ||
self.my_refs.get(key)) | ||
|
||
def tearDown(self): | ||
""" Delete the test directory. """ | ||
rmtree(self.tmp_path) | ||
|
||
def test_files_headers(self): | ||
""" | ||
Confirms that the expected output of has_valid_header is correct. | ||
""" | ||
for case in self.cases: | ||
if self.cases[case]: | ||
self.assertTrue(has_valid_header(case, self.my_refs, | ||
self.my_regex)) | ||
else: | ||
self.assertFalse(has_valid_header(case, self.my_refs, | ||
self.my_regex)) | ||
|
||
def test_invalid_count(self): | ||
""" | ||
Test that the initial files found isn't zero, indicating | ||
a problem with the code. | ||
""" | ||
self.assertFalse(self.prexisting_file_count == 0) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.