Skip to content

Key/Value backend #865

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

Closed
wants to merge 81 commits into from
Closed

Key/Value backend #865

wants to merge 81 commits into from

Conversation

mogorman
Copy link

@mogorman mogorman commented Feb 4, 2018

This is just the same as #624 I will make the other hundred refrence changes needed but i just wanted to get this started.

There are quite some ideas in the issue tracker about how we could improve nixops radically.

I would like to start out with a feasible iterative plan. As far as I can see, only very trivial SQL operations are every executed against the sqlite3 database; the main use case is to use transactions to support rollback in the case of exceptions. This should not be to hard to implement ourselves in memory, in combination with a key/value server that supports locking certain keys.

  • Refactor the statefile and deployment lock into a specific local implementation
  • Introduce different URI schema's for future backends
  • Refactor all the sqlite3 queries into concrete operations implemented in file.Statefile
  • Deployment
  • Resource
  • VirtualBox
  • None backend done, needs to be verified
  • GCE done, needs to be verified
  • AWS done, needs to be verified
  • Hetzner done, needs to be verified
  • Implement a local json file backend
  • Fix unit tests

moretea added 30 commits March 13, 2017 19:42
Needed to faclitate multiple backends (like sqlite3/other remote database)
For now it's just the underlying DB, but it resembles something that
can roll back the current transaction.
@mogorman
Copy link
Author

I reduced the scope of this back to just the sqlite and json work. I will make another fork to add in mysql/postgresql support. What is here works. I also added a unit test for testing the json backend, but couldnt figure out how to run just it i tried

python2 tests.py tests.functional.generic_json_deployment_test 

but it kept giving me libvirt errors. I didn't have interest in running all the tests on my laptop. is there a way to kick off the bot on it @grahamc

I am done with this iteration unless others have requests I think it is good to go.

@moretea
Copy link
Contributor

moretea commented Feb 17, 2018

@rbvermaas I also ran into those libvirt issues. I remember that you said that those have not worker properly at all?

@mogorman could you check if those tests do, or do not work on the master branch?

@mogorman
Copy link
Author

@moretea if im not mistaken ive fixed all the tests but i was hoping someone with gce, aws, etc could run them all

@moretea
Copy link
Contributor

moretea commented Feb 17, 2018

As far as I can remember, I tried the local virtualbox backend, and GCE. Both worked.

I could check out AWS & GCE later, but am on a holiday this weekend and don't have time 🙈

@AmineChikhaoui
Copy link
Member

Hi @mogorman , VPC tests seem to be broken e.g:

Traceback (most recent call last):
  File "/nix/store/f8phnzpvr67l1r18xbhbwsr4cskqacys-python-2.7.14/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/nix/store/f8phnzpvr67l1r18xbhbwsr4cskqacys-python-2.7.14/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/amine/src/nixops/tests/__init__.py", line 18, in destroy
    depl = sf.open_deployment(uuid)
  File "/home/amine/src/nixops/nixops/state/sqlite_connector.py", line 148, in open_deployment
    deployment = self._find_deployment(uuid=uuid)
  File "/home/amine/src/nixops/nixops/state/sqlite_connector.py", line 144, in _find_deployment
    return nixops.deployment.Deployment(self, res[0][0], sys.stderr)
  File "/home/amine/src/nixops/nixops/deployment.py", line 78, in __init__
    self.resources = self._state.get_resources_for(self)
  File "/home/amine/src/nixops/nixops/state/sqlite_connector.py", line 242, in get_resources_for
    r = self._create_state(deployment, type, name, id)
  File "/home/amine/src/nixops/nixops/state/sqlite_connector.py", line 394, in _create_state
    return cls(depl, name, id)
  File "/home/amine/src/nixops/nixops/resources/vpc.py", line 43, in __init__
    self.vpc_id = self._state.get('vpcId', None)
  File "/nix/store/f8phnzpvr67l1r18xbhbwsr4cskqacys-python-2.7.14/lib/python2.7/_abcoll.py", line 382, in get
    return self[key]
  File "/home/amine/src/nixops/nixops/state/state_helper.py", line 22, in __getitem__
    value = self._state.get_resource_attr(self.uuid, self.id, name)
NameError: global name 'name' is not defined

@tomberek
Copy link
Contributor

I like using nixops-manager and ran into this issue. Seems like it has to do with escaping in JSON.

[nix-shell:~/cloud]$ ./manage gce create '<cloud.nix>'                         
created deployment ‘56c8f9ee-14ef-11e8-aad6-00163e000000’                      
56c8f9ee-14ef-11e8-aad6-00163e000000 

[nix-shell:~/cloud]$ ./manage gce deploy                                                                                                                      
error: getting status of ‘/home/dev/cloud/\<cloud.nix\>’: No such file or directory                                                                           
error: evaluation of the deployment specification failed    

[nix-shell:~/cloud]$ cat gce.json      
{
  "schemaVersion": 0, 
  "deployments": {
    "56c8f9ee-14ef-11e8-aad6-00163e000000": {
      "attributes": {
        "nixExprs": "[\"/home/dev/cloud/\\\\<cloud.nix\\\\>\"]", 
        "name": "gce"
      }, 
      "resources": {}
    }
  }
}

using a normal (non bracketed path) seems to work well for gce

[nix-shell:~/cloud]$ ./manage gce create './cloud.nix'                                                                                                        
created deployment ‘d3fcdf3d-14ef-11e8-900d-00163e000000’                      
d3fcdf3d-14ef-11e8-900d-00163e000000   

[nix-shell:~/cloud]$ ./manage gce deploy                                       
bootstrap> creating GCE image 'n-d3fcdf3d14ef11e8900d00163e000000-bootstrap'... 

...
[nix-shell:~/cloud]$ ./manage gce destroy
warning: are you sure you want to destroy GCE machine 'n-d3fcdf3d14ef11e8900d00163e000000-single'? (y/N) y
single...> destroying the GCE machine...
...

@mogorman
Copy link
Author

Thanks I'll look at these now

@mogorman
Copy link
Author

@AmineChikhaoui I believe i fixed these unit test failures with my last round of commits, they fail for me stil as I don't have aws keys but they do correctly update the attrs and get past the failure point you posted.

@tomberek Your issue is coming from nix-shell over escaping things. probably because you were in the dev-shell and then executed another deeper nix-shell. can you try installing this fork of nixops and running without the nested shells? this error does not happen to me when i used <> directly

{
  "schemaVersion": 0, 
  "deployments": {
    "8f9506b0-153e-11e8-839e-024290535936": {
      "attributes": {
        "nixExprs": "[\"<trivial.nix>\", \"<trivial-vbox.nix>\"]", 
        "name": "test", 
        "configsPath": "/nix/store/dm9a1cixp8w7mylzv6vhpwv7nj0i2kqr-nixops-machines", 
        "description": "Web server"
      }, 
      "resources": {}
    }
  }
}

@AmineChikhaoui
Copy link
Member

@mogorman Thanks, so the previous errors are gone but I still see some errors during the deployment tear down in the unit tests, can't post them now because it exposes some resources IDs and AWS debug output but I'll re-run it later this week and look at the errors.

@mogorman
Copy link
Author

@AmineChikhaoui did you ever get a chance to get me more info as to what is broken? or can anyone help me understand how to run the test framework better? the only errors i get when running tests are those caused by lack of aws gce etc credentials so i assume the other tests passed?

@andrewchambers
Copy link

Could someone explain the rationale for this change? what is the point?

@mogorman
Copy link
Author

mogorman commented Mar 9, 2018

the point of providing a plugable state backend is to make it easier for people to work with nixops. In the case of the json one, it makes it much easier to commit these things to git and share them among a team, in the future I want to make a mysql/postgresql backend as well so that I can manage the state there. Others have requested a backend using s3 and simpledb. this work makes it easier to do all these things.

@moretea
Copy link
Contributor

moretea commented Mar 9, 2018

Having a json file is the starting point to prove that we can use any K/V store. Once that's done, adding e.g. mysql, or S3 + DynamoDB should just work fine.

@gleber-da
Copy link

👍 to these changes. These would help us share the workload of managing our deployments in the team.

@nh2
Copy link
Contributor

nh2 commented May 27, 2018

What's the state currently? Do you only need testers for the 3 remaining backends?

@moretea
Copy link
Contributor

moretea commented May 29, 2018

@nh2 talking to me? And which backends are you referring to?

@nh2
Copy link
Contributor

nh2 commented May 29, 2018

To whomever would like this PR in, really. I was referring to

  • None backend done, needs to be verified
  • GCE done, needs to be verified
  • AWS done, needs to be verified
  • Hetzner done, needs to be verified

in the issue description.

@tomberek
Copy link
Contributor

tomberek commented Nov 4, 2018

What is needed for this? Do you need user reports and testing?

@domenkozar
Copy link
Member

See #1264

@grahamc
Copy link
Member

grahamc commented Mar 26, 2020

Hello!

Thank you for this PR.

In the past several months, some major changes have taken place in
NixOps:

  1. Backends have been removed, preferring a plugin-based architecture.
    Here are some of them:

  2. NixOps Core has been updated to be Python 3 only, and at the
    same time, MyPy type hints have been added and are now strictly
    required during CI.

This is all accumulating in to what I hope will be a NixOps 2.0
release
. There is a tracking issue for that:
#1242 . It is possible that
more core changes will be made to NixOps for this release, with a
focus on simplifying NixOps core and making it easier to use and work
on.

My hope is that by adding types and more thorough automated testing,
it will be easier for contributors to make improvements, and for
contributions like this one to merge in the future.

However, because of the major changes, it has become likely that this
PR cannot merge right now as it is. The backlog of now-unmergable PRs
makes it hard to see which ones are being kept up to date.

If you would like to see this merge, please bring it up to date with
master and reopen it
. If the or mypy type checking fails, please
correct any issues and then reopen it. I will be looking primarily at
open PRs whose tests are all green.

Thank you again for the work you've done here, I am sorry to be
closing it now.

Graham

@grahamc grahamc closed this Mar 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants