Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key value state + tests refactoring #969

Closed
wants to merge 129 commits into from
Closed
Show file tree
Hide file tree
Changes from 125 commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
7035abe
Move statefile into state.file module
moretea Mar 13, 2017
6da031f
Introduce different state state schemes.
moretea Mar 13, 2017
8269650
Rename statefile->state in deployment.py
moretea Mar 13, 2017
c73773f
Move file based deployment lock to file state implementation.
moretea Mar 13, 2017
8a4e34a
Fix indenting
moretea Mar 13, 2017
bb056ea
Bite the bullet; remove _db references from business objects + rename…
moretea Mar 13, 2017
6cc171a
move get_resources_for
moretea Mar 13, 2017
813a231
move set_deployment_attrs
moretea Mar 13, 2017
7b58934
move del_deployment_attr
moretea Mar 13, 2017
7ed3fd3
move get_deployment_attr
moretea Mar 13, 2017
0db686d
move create_resource
moretea Mar 13, 2017
97e0714
Move most logic in export() to get_all_deployment_attrs in statefile.
moretea Mar 13, 2017
584d658
Make import use an atomic transaction thingy.
moretea Mar 13, 2017
97bda1a
move clone_deployment
moretea Mar 13, 2017
77e9b93
move part of delete_resource
moretea Mar 13, 2017
4d33f93
missed a few _'s
moretea Mar 13, 2017
5649e39
move part of delete to _delete_deployment
moretea Mar 13, 2017
4075901
use state atomic
moretea Mar 13, 2017
5f39278
Move part of logic of rename to _rename_resource
moretea Mar 13, 2017
6605128
oh yeah, I did rename _db to __db!
moretea Mar 13, 2017
5881c06
Use atomic instead of _db
moretea Mar 13, 2017
de9d700
Use atomic instead of _db
moretea Mar 13, 2017
ff23c1c
move set_resource_attrs
moretea Mar 13, 2017
eb2a24a
move del_resource_attr
moretea Mar 13, 2017
47b3a43
move get_resource_attr
moretea Mar 13, 2017
6835823
move part of export to get_all_resource_attrs
moretea Mar 13, 2017
3739051
Use atomic instead of _db
moretea Mar 13, 2017
66dee1d
oh yeah, I did rename _db to __db!
moretea Mar 13, 2017
6254ccb
simple typo's
moretea Mar 13, 2017
2d1a822
Need to pass in object; too much coupling to refactor right now
moretea Mar 13, 2017
20c5e89
missed assigning to local dict
moretea Mar 13, 2017
6c37bbd
typo
moretea Mar 13, 2017
4baebf9
missing subclass function. Just copied for now
moretea Mar 13, 2017
44652be
typo
moretea Mar 13, 2017
e238874
locally reachable already
moretea Mar 13, 2017
56c39b7
missed the self parameter
moretea Mar 13, 2017
83b5ca1
use _state.atomic instead of _db
moretea Mar 14, 2017
abf3d6e
schema: file -> sqlite3
moretea Mar 14, 2017
0d999cf
Fix _rename_resource, needs resource_id
moretea Mar 14, 2017
a08de62
WIP: initial json backend.
moretea Mar 14, 2017
6baf57f
Include the deployment_uuid in the API for modifying resource attributes
moretea Mar 14, 2017
2dfa148
Small bug fixes
moretea Mar 14, 2017
6733fa7
Utilize deployment_uid
moretea Mar 14, 2017
3827e69
Also recognize json's true as a valid bool value
moretea Mar 14, 2017
056ab60
Undo split between state.atomic and state.db
moretea Mar 29, 2017
38aa181
Typo
moretea Mar 29, 2017
4aaf084
Rename file -> sqlite3_file in tests
moretea Mar 29, 2017
6950f37
Rename file -> sqlite3_file in scripts/nixops
moretea Mar 29, 2017
6576e16
Rename file -> sqlite3_file in scripts/nixops
moretea Mar 29, 2017
9d7cf8c
Merge branch 'master' into kv-state
rbvermaa Jul 24, 2017
7c34e60
Merge branch 'kv-state' of https://github.com/moretea/nixops into mor…
mogorman Feb 4, 2018
ef2f480
Merge branch 'moretea-kv-state' into kv-state
mogorman Feb 4, 2018
4ff5a24
fixed probable typo from fork
mogorman Feb 4, 2018
f7ef59f
change all instances to use state wrapper
mogorman Feb 5, 2018
47684d5
integrate new state wrapper with one from fork
mogorman Feb 5, 2018
b0f18b5
rewrite this to use the wrapper
mogorman Feb 7, 2018
b3690b0
initial commit of moving over to sqlalchemy for all sql endpoints
mogorman Feb 7, 2018
0b89b58
typo letter
mogorman Feb 7, 2018
1ab3156
working switcher code. now rewriting sql code to use sqlalchemy
mogorman Feb 7, 2018
98290e6
fixed sqlalchemy sqlite support by using internal implementation. now…
mogorman Feb 7, 2018
3863edc
working sqlalchemy
mogorman Feb 7, 2018
c11756c
removed prints
mogorman Feb 7, 2018
b42814f
beginning of porting to mysql as well. will need specific sql for cre…
mogorman Feb 7, 2018
19d3178
working mysql support
mogorman Feb 7, 2018
5d200ee
possible row exception
mogorman Feb 7, 2018
6e71adc
better locking and some temporary debugging
mogorman Feb 10, 2018
ceaf062
fix the past
mogorman Feb 12, 2018
6f4f855
fixed unit tests
mogorman Feb 12, 2018
28ac4b2
move function into the core state file
mogorman Feb 13, 2018
759b96b
this simplifies to kv / sqlite for now so that we can move forward on
mogorman Feb 14, 2018
cc70b2a
testing this theory
mogorman Feb 14, 2018
4585685
move class around
mogorman Feb 14, 2018
07278c8
test
mogorman Feb 14, 2018
76ffca7
remove debugging
mogorman Feb 14, 2018
6cf8c02
adding unit test and testing it
mogorman Feb 14, 2018
f656d58
new unit tests
mogorman Feb 14, 2018
83c4af9
remove debugging
mogorman Feb 14, 2018
4cea4d2
fix variable name issue and move subclasses to common spot among
mogorman Feb 19, 2018
f477f2a
work on unit tests
mogorman Feb 19, 2018
36f2479
make json match the behavior of sqlite
mogorman Feb 19, 2018
0a836b6
misnamed variable
mogorman Feb 19, 2018
874e7de
Merge branch 'master' into kv-state
srghma Jun 9, 2018
6be85a1
fix: OperationalError no such column True -> quote booleans
srghma Jun 9, 2018
666561c
fix: OperationalError no such column True -> use sqlite execute escaping
srghma Jun 9, 2018
dee2de2
refactor: tests -> move
srghma Jun 10, 2018
b24e69a
refactor: tests -> move files (WIP)
srghma Jun 10, 2018
d92a9cb
refactor: tests -> test_ec2_backups stops without error, but "mux_cli…
srghma Jun 10, 2018
0f607c1
refactor: tests -> test_ec2_spot_instance (WIP)
srghma Jun 10, 2018
d853354
refactor: tests -> test_deploys_nixos
srghma Jun 10, 2018
c0a21c9
refactor: tests -> using_state_file -> revert implementation to creat…
srghma Jun 10, 2018
047e237
refactor: tests -> refactor other tests, not checked (WIP)
srghma Jun 10, 2018
04f9980
refactor: tests -> make vbox test unoptional (this should be centrali…
srghma Jun 11, 2018
11aa0e3
fix: tests
srghma Jun 14, 2018
cf063be
fix(#970): tests.functional.test_ec2_rds_dbinstance -> remove default…
srghma Jun 14, 2018
e2a64a2
feat: tests -> using_state_file -> delete state file if exists before…
srghma Jun 15, 2018
8511f59
feat: tests -> using_state_file -> unique state file for each test
srghma Jun 15, 2018
0bd5210
refactor: tests -> use using_unique_state_file in some tests
srghma Jun 16, 2018
a681561
fix: json, when clone_deployment -> local variable "uuid" referenced …
srghma Jun 16, 2018
5f4cd5d
fix: tests
srghma Jun 16, 2018
f453d6e
fix: tests.functional.test_query_deployments -> No JSON object could …
srghma Jun 16, 2018
3c6433d
fix: tests (WIP)
srghma Jun 16, 2018
458771e
fix: tests -> shared -> destroy_deployments
srghma Jun 16, 2018
877b7fb
feat: clean_test_state_files.py
srghma Jun 16, 2018
59c33cd
fix: tests.functional.test_vpc:test_deploy_vpc -> works with nixops s…
srghma Jun 16, 2018
e1b9158
fix: tests.functional.test_vpc:test_deploy_vpc with json state -> Typ…
srghma Jun 16, 2018
b30dbfe
refactor: state -> _create_state repeats
srghma Jun 17, 2018
0b6c27c
refactor: test, destroy_deployments_and_remove_state_file -> print error
srghma Jun 17, 2018
898107c
fix: deployment.clean_backups method -> UnboundLocalError: local vari…
srghma Jun 17, 2018
e554c13
fix: tests.functional.test_vpc:test_deploy_vpc -> create_exprs_dir ->…
srghma Jun 17, 2018
db84a8f
fix: state_dict -> An error occurred (InvalidRouteTableId.Malformed) …
srghma Jun 17, 2018
2e547bd
fix: use isinstance(XXX, basestring) because isinstance(XXX, str) ret…
srghma Jun 17, 2018
2f930cd
refactor: tests.functional.test_vpc
srghma Jun 17, 2018
3a778db
refactor: destroy_deployments_and_remove_state_file -> change message…
srghma Jun 17, 2018
1411a5a
fix: typo in message
srghma Jun 17, 2018
c91d5a5
fix: tests.functional.test_stopping_stops -> cannot delete this deplo…
srghma Jun 17, 2018
da9b31a
refactor: destroy_deployments_and_remove_state_file -> comment becaus…
srghma Jun 17, 2018
c21aa05
refactor: test_ec2_rds_dbinstance -> add documentation and disable te…
srghma Jun 17, 2018
fd81092
fix: azure -> AzureState object has no attribute user
srghma Jun 20, 2018
7c15255
fix: comment
srghma Jun 20, 2018
c3ec96b
Merge remote-tracking branch 'upstream/master' into kv-state
srghma Nov 10, 2018
d912e7d
refactor: coretemp review -> change "echo -n" to "printf"
srghma Nov 10, 2018
b65546f
refactor: coretemp review -> fix typo -> revert "backend" to "backed"
srghma Nov 10, 2018
2ceecef
refactor: coretemp review -> fix typo -> "of" to "for"
srghma Nov 10, 2018
b63914b
refactor: coretemp review -> json_file, _find_deployment method
srghma Nov 10, 2018
b5ee915
refactor: coretemp review -> fix typo -> "michine" to "machine"
srghma Nov 10, 2018
cb411dd
Merge branch 'master' into kv-state
srghma Nov 17, 2018
c4eecfb
fix: build errors
srghma Nov 18, 2018
e0a34e8
feat: mypy -> add mypy-parametrized
srghma Nov 18, 2018
16e0b6c
fix: coretemp review -> fix typo -> change "of -> for" and revert pre…
srghma Nov 18, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ html/
result
*.sw[a-z]
tags
tests/test.nixops*
tests/state_files
15 changes: 15 additions & 0 deletions clean_test_state_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#! /usr/bin/env python2
# -*- coding: utf-8 -*-

from nixops.util import root_dir
from tests.functional.shared.destroy_deployments_and_remove_state_file import destroy_deployments_and_remove_state_file
from tests.functional.shared.state_files_directory import state_files_directory
import os

for file in os.listdir(state_files_directory):
if file.endswith(".nixops") or file.endswith(".json"):
file_path = os.path.join(state_files_directory, file)

print("Destroying {}".format(file_path))

destroy_deployments_and_remove_state_file(file_path)
2 changes: 1 addition & 1 deletion nix/ec2-rds-dbinstance.nix
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ with import ./lib.nix lib;
};

securityGroups = mkOption {
default = [ "default" ];
default = [ ];
type = types.listOf (types.either types.str (resource "ec2-rds-security-group"));
apply = map (x: if builtins.isString x then x else "res-" + x._name);
description = ''
Expand Down
2 changes: 1 addition & 1 deletion nix/ec2-rds-dbsecurity-group.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ with import ./lib.nix lib;
type = types.str;
description = ''
Description of the RDS DB security group.
'';
'';
};

region = mkOption {
Expand Down
2 changes: 1 addition & 1 deletion nix/hetzner-bootstrap.nix
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ in stdenv.mkDerivation {
echo 'scriptheadsize="$(head -n ''${lnum%%:*} "'"$installer"'" | wc -c)"'
echo 'scriptsize="$(${pkgsNative.coreutils}/bin/stat -c %s "'"$installer"'")"'
echo 'tarsize="$(($scriptsize - $scriptheadsize))"'
echo 'echo -n "$tarsize:"'
echo 'printf "$tarsize:"'
echo 'tail -n +$((''${lnum%%:*} + 1)) "'"$installer"'"'
# As before, don't quote here!
echo '${pkgsNative.gnutar}/bin/tar c -C /' $stripped_full_storepaths
Expand Down
5 changes: 2 additions & 3 deletions nixops/backends/azure_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ def start(self):

def stop(self):
if self.vm_id:
#FIXME: there's also "stopped deallocated" version of this. how to integrate?
# FIXME: there's also "stopped deallocated" version of this. how to integrate?
self.log("stopping Azure machine... ")
self.state = self.STOPPING
self.cmc().virtual_machines.power_off(self.resource_group, self.machine_name)
Expand Down Expand Up @@ -1170,8 +1170,7 @@ def get_backups(self):


def _check(self, res):
if(self.subscription_id is None or self.authority_url is None or
self.user is None or self.password is None):
if(self.subscription_id is None or self.authority_url is None):
res.exists = False
res.is_up = False
self.state = self.MISSING;
Expand Down
24 changes: 15 additions & 9 deletions nixops/backends/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def __init__(self, depl, name, id):

def _reset_state(self):
"""Discard all state pertaining to an instance."""
with self.depl._db:
with self.depl._state.db:
self.state = MachineState.MISSING
self.associate_public_ip_address = None
self.use_private_ip_address = None
Expand Down Expand Up @@ -373,7 +373,7 @@ def _instance_ip_ready(ins):

self.log_end("{0} / {1}".format(instance.ip_address, instance.private_ip_address))

with self.depl._db:
with self.depl._state.db:
self.private_ipv4 = instance.private_ip_address
self.public_ipv4 = instance.ip_address
self.public_dns_name = instance.public_dns_name
Expand Down Expand Up @@ -655,7 +655,7 @@ def _assign_elastic_ip(self, elastic_ipv4, check):

nixops.known_hosts.update(self.public_ipv4, elastic_ipv4, self.public_host_key)

with self.depl._db:
with self.depl._state.db:
self.elastic_ipv4 = elastic_ipv4
self.public_ipv4 = elastic_ipv4
self.ssh_pinged = False
Expand All @@ -668,7 +668,7 @@ def _assign_elastic_ip(self, elastic_ipv4, check):
else:
self.log("address ‘{0}’ was not associated with instance ‘{1}’".format(self.elastic_ipv4, self.vm_id))

with self.depl._db:
with self.depl._state.db:
self.elastic_ipv4 = None
self.public_ipv4 = None
self.ssh_pinged = False
Expand Down Expand Up @@ -732,7 +732,7 @@ def create_instance(self, defn, zone, devmap, user_data, ebs_optimized):
lambda: self._conn.request_spot_instances(price=defn.spot_instance_price/100.0, **common_args)
)[0]

with self.depl._db:
with self.depl._state.db:
self.spot_instance_price = defn.spot_instance_price
self.spot_instance_request_id = request.id

Expand Down Expand Up @@ -763,7 +763,7 @@ def create_instance(self, defn, zone, devmap, user_data, ebs_optimized):
# the instance ID, we'll get the same instance ID on the
# next run.
if not self.client_token:
with self.depl._db:
with self.depl._state.db:
self.client_token = nixops.util.generate_random_string(length=48) # = 64 ASCII chars
self.state = self.STARTING

Expand Down Expand Up @@ -982,7 +982,7 @@ def create(self, defn, check, allow_reboot, allow_recreate):
# Generate a public/private host key.
if not self.public_host_key:
(private, public) = nixops.util.create_key_pair(type=defn.host_key_type())
with self.depl._db:
with self.depl._state.db:
self.public_host_key = public
self.private_host_key = private

Expand All @@ -993,7 +993,7 @@ def create(self, defn, check, allow_reboot, allow_recreate):
instance = self.create_instance(defn, zone, devmap, user_data, ebs_optimized)
update_instance_profile = False

with self.depl._db:
with self.depl._state.db:
self.vm_id = instance.id
self.ami = defn.ami
self.instance_type = defn.instance_type
Expand Down Expand Up @@ -1088,7 +1088,7 @@ def create(self, defn, check, allow_reboot, allow_recreate):
elastic_ipv4 = res.public_ipv4
self._assign_elastic_ip(elastic_ipv4, check)

with self.depl._db:
with self.depl._state.db:
self.use_private_ip_address = defn.use_private_ip_address
self.associate_public_ip_address = defn.associate_public_ip_address

Expand Down Expand Up @@ -1351,7 +1351,10 @@ def destroy(self, wipe=False):
# in create() due to it being interrupted after the instance
# was created but before it registered the ID in the database.
self.connect()
self.connect_boto3()

instance = None

if self.vm_id:
instance = self._get_instance(allow_missing=True)
else:
Expand All @@ -1369,6 +1372,9 @@ def destroy(self, wipe=False):
time.sleep(3)
instance = self._get_instance(update=True)

# this will prevent `cannot delete ec2-security-group because it still has resources` error
nixops.ec2_utils.wait_for_network_interfaces_deattached(self._conn_boto3, self.vm_id)

self.log_end("")

nixops.known_hosts.update(self.public_ipv4, None, self.public_host_key)
Expand Down
4 changes: 2 additions & 2 deletions nixops/backends/hetzner.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def create(self, defn, check, allow_reboot, allow_recreate):
self.log_start("creating an exclusive robot admin sub-account "
"for ‘{0}’... ".format(self.name))
server = self._get_server_from_main_robot(self.main_ipv4, defn)
with self.depl._db:
with self.depl._state.db:
(self.robot_admin_user,
self.robot_admin_pass) = server.admin.create()
self.log_end("done. ({0})".format(self.robot_admin_user))
Expand All @@ -609,7 +609,7 @@ def create(self, defn, check, allow_reboot, allow_recreate):
)
if robot_user != self.robot_admin_user or \
robot_pass != self.robot_admin_pass:
with self.depl._db:
with self.depl._state.db:
(self.robot_admin_user,
self.robot_admin_pass) = (robot_user, robot_pass)

Expand Down
5 changes: 3 additions & 2 deletions nixops/backends/virtualbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def _update_ip(self):
capture_stdout=True).rstrip()
if res[0:7] != "Value: ": return
new_address = res[7:]

nixops.known_hosts.update(self.private_ipv4, new_address, self.public_host_key)
self.private_ipv4 = new_address

Expand Down Expand Up @@ -194,7 +195,7 @@ def create(self, defn, check, allow_reboot, allow_recreate):
# Generate a public/private host key.
if not self.public_host_key:
(private, public) = nixops.util.create_key_pair()
with self.depl._db:
with self.depl._state.db:
self.public_host_key = public
self.private_host_key = private

Expand All @@ -203,7 +204,7 @@ def create(self, defn, check, allow_reboot, allow_recreate):

# Backwards compatibility.
if self.disk:
with self.depl._db:
with self.depl._state.db:
self._update_disk("disk1", {"created": True, "path": self.disk,
"attached": self.disk_attached,
"port": 0})
Expand Down
Loading