def test_protocol_types_list(site_client, protocol_type, protocol_attribute, protocol_attribute2): """Test ``nsot protocol_types list``""" runner = CliRunner(site_client.config) with runner.isolated_filesystem(): # Basic List. result = runner.run('protocol_types list') assert result.exit_code == 0 assert protocol_type['name'] in result.output # Test -d/--description result = runner.run('protocol_types list -d "%s"' % protocol_type['description']) assert result.exit_code == 0 assert protocol_type['description'] in result.output # Test -n/--name result = runner.run('protocol_types list -n %s' % protocol_type['name']) assert result.exit_code == 0 assert protocol_type['name'] in result.output # Test -s/--site result = runner.run('protocol_types list -s %s' % protocol_type['site']) assert result.exit_code == 0 assert protocol_type['name'] in result.output # Test -i/--id result = runner.run('protocol_types list -i %s' % protocol_type['id']) assert result.exit_code == 0 assert protocol_type['name'] in result.output
def test_protocols_update(site_client, interface_a, device_a, site, circuit, protocol, protocol_attribute): site_id = str(protocol['site']) proto_id = protocol['id'] runner = CliRunner(site_client.config) with runner.isolated_filesystem(): # Update description result = runner.run('protocols update -i %s -e "bees buzz"' % proto_id) assert result.exit_code == 0 assert 'Updated protocol!' in result.output # Ensure that buzz is not the bizness result = runner.run('protocols list') assert result.exit_code == 0 assert 'buzz' in result.output assert 'bizness' not in result.output # Add an attribute result = runner.run( 'protocols update -i %s --add-attributes -a boo=test_attribute' % proto_id ) assert result.exit_code == 0 assert 'Updated protocol!' in result.output result = runner.run('protocols list') assert result.exit_code == 0 assert 'test_attribute' in result.output # Add an attribute without using --add-attributes. result = runner.run( 'protocols update -i %s -a boo=test_attribute' % proto_id ) assert result.exit_code == 0 assert 'Updated protocol!' in result.output result = runner.run('protocols list') assert result.exit_code == 0 assert 'test_attribute' in result.output # Delete an attribute result = runner.run( 'protocols update -i %s --delete-attributes -a foo=test_protocol' % proto_id ) assert result.exit_code == 0 assert 'Updated protocol!' in result.output result = runner.run('protocols list') assert result.exit_code == 0 assert 'test_protocol' not in result.output # Replace an attribute result = runner.run( 'protocols update -i %s --replace-attributes -a foo=test_replace' % proto_id ) assert result.exit_code == 0 assert 'Updated protocol!' in result.output result = runner.run('protocols list') assert result.exit_code == 0 assert 'test_protocol' not in result.output assert 'test_replace' in result.output
def test_protocol_types_update(site_client, protocol_type, protocol_attribute): """Test ``nsot protocol_types update``""" pt_id = protocol_type['id'] runner = CliRunner(site_client.config) with runner.isolated_filesystem(): # Try to change the name result = runner.run('protocol_types update -n Cake -i %s' % (pt_id)) assert result.exit_code == 0 assert 'Updated protocol_type!' in result.output # Update the description result = runner.run('protocol_types update -d Rise -i %s' % (pt_id)) assert result.exit_code == 0 assert 'Updated protocol_type!' in result.output # Assert the Cake Rises result = runner.run('protocol_types list -i %s' % pt_id) assert result.exit_code == 0 assert 'Cake' in result.output assert 'Rise' in result.output # Test add attributes result = runner.run('protocol_types update -r %s -i %s' % ( protocol_attribute['name'], pt_id, )) assert result.exit_code == 0 assert 'Updated protocol_type!' in result.output # Assert the attribute was added result = runner.run('protocol_types list -i %s' % pt_id) assert result.exit_code == 0 assert protocol_attribute['name'] in result.output
def test_protocol_types_remove(site_client, protocol_type): """Test ``nsot protocol_types remove``""" runner = CliRunner(site_client.config) with runner.isolated_filesystem(): result = runner.run('protocol_types remove -i %s' % (protocol_type['id'])) assert result.exit_code == 0 assert 'Removed protocol_type!' in result.output
def test_protocols_remove(site_client, protocol): runner = CliRunner(site_client.config) with runner.isolated_filesystem(): result = runner.run('protocols remove -i %s -s %s' % (protocol['id'], protocol['site'])) assert result.exit_code == 0 result = runner.run('protocols list') assert result.exit_code == 0 assert 'No protocol found' in result.output
def test_protocols_list(site_client, device_a, interface_a, site, circuit, protocol): """Test ``nsot protocols list``""" device_id = str(device_a['id']) interface_id = str(interface_a['id']) protocol_id = str(protocol['id']) runner = CliRunner(site_client.config) with runner.isolated_filesystem(): result = runner.run('protocols list') assert result.exit_code == 0 assert 'bgp' in result.output # test -t/--type result = runner.run('protocols list -t bgp') assert result.exit_code == 0 assert 'bgp' in result.output # Test -D/--device result = runner.run('protocols list -D %s' % device_id) assert result.exit_code == 0 assert device_a['hostname'] in result.output # Test -I/--interface result = runner.run('protocols list -I %s' % interface_id) assert result.exit_code == 0 assert interface_a['name_slug'] in result.output # Test -a/--attributes result = runner.run('protocols list -a foo=test_protocol') assert result.exit_code == 0 assert protocol['attributes']['foo'] in result.output # Test -c/--circuit result = runner.run('protocols list -c %s' % circuit['name']) assert result.exit_code == 0 assert circuit['name'] in result.output # Test -e/--description result = runner.run('protocols list -e "%s"' % protocol['description']) assert result.exit_code == 0 assert protocol['description'] in result.output # Test -I/--id result = runner.run('protocols list -i %s' % protocol_id) assert result.exit_code == 0 assert protocol_id in result.output # Test -q/--query slug = '{device}:{type}:{id}'.format(**protocol) result = runner.run('protocols list -q foo=test_protocol') assert result.exit_code == 0 assert slug in result.output
def test_protocol_types_list_limit(site_client, protocol_types): """ If ``--limit 2`` is used, we should only see the first two Protocol objects """ limit = 2 runner = CliRunner(site_client.config) with runner.isolated_filesystem(): result = runner.run('protocol_types list -l {}'.format(limit)) assert result.exit_code == 0 expected_types = protocol_types[:limit] unexpected_types = protocol_types[limit:] for t in expected_types: assert t['name'] in result.output for t in unexpected_types: assert t['name'] not in result.output
def test_protocol_types_add(site_client, protocol_attribute): """Test ``nsot protocol_types add``.""" runner = CliRunner(site_client.config) with runner.isolated_filesystem(): # Add a protocol_type by name. result = runner.run("protocol_types add -n bgp") assert result.exit_code == 0 assert 'Added protocol_type!' in result.output # Verify addition. result = runner.run('protocol_types list') assert result.exit_code == 0 assert 'bgp' in result.output # Add a protocol with same name and fail. result = runner.run("protocol_types add -n bgp") expected_output = 'The fields site, name must make a unique set.' assert result.exit_code != 0 assert expected_output in result.output # Add second protocol_type by name. result = runner.run("protocol_types add -n ospf -d 'OSPF is the best'") assert result.exit_code == 0 assert 'Added protocol_type!' in result.output # Verify default site is assigned and verify description. site_id = str(protocol_attribute['site_id']) result = runner.run('protocol_types list -i 2') assert result.exit_code == 0 assert site_id in result.output assert 'OSPF is the best' in result.output # Add a third protocol type with required_attribute. result = runner.run('protocol_types add -n tcp -r %s' % protocol_attribute['name']) assert result.exit_code == 0 assert 'Added protocol_type!' in result.output # Verify protocol attribute is assigned. result = runner.run('protocol_types list -n tcp') assert result.exit_code == 0 assert protocol_attribute['name'] in result.output
def test_protocols_list_offset(site_client, protocols): """ If ``--limit 2`` and ``--offset 2`` are used, we should only see the third and fourth Protocol objects that were created """ limit = 2 offset = 2 runner = CliRunner(site_client.config) with runner.isolated_filesystem(): result = runner.run('protocols list -l {} -o {}'.format(limit, offset)) assert result.exit_code == 0 expected_protocols = protocols[offset:limit + offset] unexpected_protocols = protocols[limit + offset:] for p in expected_protocols: assert p['device'] in result.output for p in unexpected_protocols: assert p['device'] not in result.output
def test_protocols_add(site_client, device_a, interface_a, site, protocol_type): """Test ``nsot protocol add``.""" device_id = str(device_a['id']) interface_id = str(interface_a['id']) runner = CliRunner(site_client.config) with runner.isolated_filesystem(): # Add a protocol. result = runner.run( "protocols add -t bgp -D %s -I %s -e 'my new proto'" % (device_id, interface_id) ) assert result.exit_code == 0 assert 'Added protocol!' in result.output # Verify addition. result = runner.run('protocols list') assert result.exit_code == 0 assert 'bgp' in result.output assert device_a['hostname'] in result.output assert 'my new proto' in result.output # Add a second protocol with attributes. attributes = 'foo=test_attribute' result = runner.run( "protocols add -t bgp -D %s -I %s -a %s" % (device_id, interface_id, attributes) ) assert result.exit_code == 0 assert 'Added protocol!' in result.output # Verify addition. result = runner.run('protocols list') assert result.exit_code == 0 assert 'bgp' in result.output assert device_a['hostname'] in result.output assert attributes in result.output