Author: sandervanderburg
Date: Mon Feb 13 12:37:35 2012
New Revision: 32256
URL: https://nixos.org/websvn/nix/?rev=32256&sc=1
Log:
Added minimal network generator, which removes all the machines from the
infrastructure model which aren't needed for deployment
Added:
disnix/disnixtesting/trunk/src/genminimalnetwork/
disnix/disnixtesting/trunk/src/genminimalnetwork/Makefile.am
disnix/disnixtesting/trunk/src/genminimalnetwork/genminimalnetwork.c
disnix/disnixtesting/trunk/src/genminimalnetwork/genminimalnetwork.h
disnix/disnixtesting/trunk/src/genminimalnetwork/main.c
Modified:
disnix/disnixtesting/trunk/configure.ac
disnix/disnixtesting/trunk/data/testing.nix.in
disnix/disnixtesting/trunk/src/Makefile.am
disnix/disnixtesting/trunk/src/gennetwork/gennetwork.c
Modified: disnix/disnixtesting/trunk/configure.ac
==============================================================================
--- disnix/disnixtesting/trunk/configure.ac Mon Feb 13 12:31:34 2012
(r32255)
+++ disnix/disnixtesting/trunk/configure.ac Mon Feb 13 12:37:35 2012
(r32256)
@@ -50,6 +50,7 @@
src/Makefile
src/test/Makefile
src/gennetwork/Makefile
+src/genminimalnetwork/Makefile
data/testing.nix
data/Makefile
])
Modified: disnix/disnixtesting/trunk/data/testing.nix.in
==============================================================================
--- disnix/disnixtesting/trunk/data/testing.nix.in Mon Feb 13 12:31:34
2012 (r32255)
+++ disnix/disnixtesting/trunk/data/testing.nix.in Mon Feb 13 12:37:35
2012 (r32256)
@@ -71,6 +71,33 @@
buildInputs = [ disnixtesting ];
buildCommand = "disnixtest-gennetwork ${servicesXMLFile}
${configurationFile} > $out";
};
+
+ generateMinimalNetworkFile = {manifest, manifestSrc, servicesFile,
networkFile, configurationFile}:
+ let
+ infrastructureFile = import
"${disnixos}/share/disnixos/generate-infrastructure.nix" {
+ networkFiles = [ networkFile ];
+ useBackdoor = true;
+ useVMTesting = true;
+ inherit nixpkgs nixos;
+ };
+
+ pkgs = import nixpkgs { inherit system; };
+
+ filters = import "${dydisnix}/share/dydisnix/filters.nix" {
+ inherit pkgs;
+ };
+
+ infrastructure = import infrastructureFile;
+
+ infrastructureXMLFile = filters.generateInfrastructureXML infrastructure;
+ in
+ with pkgs;
+
+ stdenv.mkDerivation {
+ name = "minimal-network.nix";
+ buildInputs = [ disnixtesting ];
+ buildCommand = "disnixtest-genminimalnetwork ${manifest}/manifest.xml
${infrastructureXMLFile} ${configurationFile} > $out";
+ };
in
{
buildManifest =
@@ -108,11 +135,13 @@
manifestSrc = generateManifestSrc {
inherit name tarball;
};
+
+ networkFile = generateNetworkFile { servicesFile =
"${manifestSrc}/${servicesFile}"; configurationFile =
"${manifestSrc}/${configurationFile}"; };
in
disnixosTest.disnixTest {
inherit name manifest tarball;
- networkFile = generateNetworkFile { servicesFile =
"${manifestSrc}/${servicesFile}"; configurationFile =
"${manifestSrc}/${configurationFile}"; };
+ networkFile = generateMinimalNetworkFile { inherit manifest manifestSrc
servicesFile networkFile; configurationFile =
"${manifestSrc}/${configurationFile}"; };
externalNetworkFile = true;
testScript = ''
Modified: disnix/disnixtesting/trunk/src/Makefile.am
==============================================================================
--- disnix/disnixtesting/trunk/src/Makefile.am Mon Feb 13 12:31:34 2012
(r32255)
+++ disnix/disnixtesting/trunk/src/Makefile.am Mon Feb 13 12:37:35 2012
(r32256)
@@ -1 +1 @@
-SUBDIRS = test gennetwork
+SUBDIRS = test gennetwork genminimalnetwork
Added: disnix/disnixtesting/trunk/src/genminimalnetwork/Makefile.am
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ disnix/disnixtesting/trunk/src/genminimalnetwork/Makefile.am Mon Feb
13 12:37:35 2012 (r32256)
@@ -0,0 +1,8 @@
+AM_CPPFLAGS = -ggdb
+
+bin_PROGRAMS = disnixtest-genminimalnetwork
+noinst_HEADERS = genminimalnetwork.h
+
+disnixtest_genminimalnetwork_SOURCES = genminimalnetwork.c main.c
+disnixtest_genminimalnetwork_LDADD = $(GLIB_LIBS) $(DISNIX_LIBS) -lmanifest
$(DYDISNIX_LIBS) -linfproperties
+disnixtest_genminimalnetwork_CFLAGS = $(GLIB_CFLAGS) $(DISNIX_CFLAGS)
$(DYDISNIX_CFLAGS)
Added: disnix/disnixtesting/trunk/src/genminimalnetwork/genminimalnetwork.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ disnix/disnixtesting/trunk/src/genminimalnetwork/genminimalnetwork.c
Mon Feb 13 12:37:35 2012 (r32256)
@@ -0,0 +1,62 @@
+#include "genminimalnetwork.h"
+#include "activationmapping.h"
+#include "infrastructureproperties.h"
+
+void generate_minimal_network(const char *manifest_file, const char
*infrastructure_xml, const char *machine_expr)
+{
+ GArray *activation_array = create_activation_array(manifest_file);
+ GArray *infrastructure_property_array =
create_infrastructure_property_array(infrastructure_xml);
+ GArray *result = g_array_new(FALSE, FALSE, sizeof(gchar*));
+ unsigned int i;
+
+ for(i = 0; i < infrastructure_property_array->len; i++)
+ {
+ Target *current_target = g_array_index(infrastructure_property_array,
Target*, i);
+ InfrastructureProperty *hostname_property =
lookup_infrastructure_property(current_target, "hostname");
+ unsigned int j;
+
+ for(j = 0; j < activation_array->len; j++)
+ {
+ ActivationMapping *mapping = g_array_index(activation_array,
ActivationMapping*, j);
+ unsigned int k;
+ char *hostname = NULL;
+
+ /* Find the hostname property */
+ for(k = 0; k < mapping->target->len; k++)
+ {
+ TargetProperty *target_property =
g_array_index(mapping->target, TargetProperty*, k);
+
+ if(g_strcmp0("hostname", target_property->name) == 0)
+ {
+ hostname = target_property->value;
+ break;
+ }
+ }
+
+ /* Check whether the target is the same */
+ if(g_strcmp0(hostname_property->value, hostname) == 0)
+ {
+ g_array_append_val(result, hostname_property->value);
+ break;
+ }
+ }
+ }
+
+ /* Print the resulting expression */
+
+ g_print("{\n");
+
+ for(i = 0; i < result->len; i++)
+ {
+ gchar *target = g_array_index(result, gchar*, i);
+ g_print(" %s = import \"%s\";\n", target, machine_expr);
+ }
+
+ g_print("}\n");
+
+ /* Cleanup */
+
+ g_array_free(result, TRUE);
+ delete_infrastructure_property_array(infrastructure_property_array);
+ delete_activation_array(activation_array);
+}
Added: disnix/disnixtesting/trunk/src/genminimalnetwork/genminimalnetwork.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ disnix/disnixtesting/trunk/src/genminimalnetwork/genminimalnetwork.h
Mon Feb 13 12:37:35 2012 (r32256)
@@ -0,0 +1,6 @@
+#ifndef __DISNIXTESTING_GENERATEMINIMALNETWORK_H
+#define __DISNIXTESTING_GENERATEMINIMALNETWORK_H
+
+void generate_minimal_network(const char *manifest_file, const char
*infrastructure_xml, const char *machine_expr);
+
+#endif
Added: disnix/disnixtesting/trunk/src/genminimalnetwork/main.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ disnix/disnixtesting/trunk/src/genminimalnetwork/main.c Mon Feb 13
12:37:35 2012 (r32256)
@@ -0,0 +1,7 @@
+#include "genminimalnetwork.h"
+
+int main(int argc, char *argv[])
+{
+ generate_minimal_network(argv[1], argv[2], argv[3]);
+ return 0;
+}
Modified: disnix/disnixtesting/trunk/src/gennetwork/gennetwork.c
==============================================================================
--- disnix/disnixtesting/trunk/src/gennetwork/gennetwork.c Mon Feb 13
12:31:34 2012 (r32255)
+++ disnix/disnixtesting/trunk/src/gennetwork/gennetwork.c Mon Feb 13
12:37:35 2012 (r32256)
@@ -9,7 +9,7 @@
g_print("{\n");
for(i = 0; i < service_property_array->len; i++)
- g_print(" test%d = import %s;\n", i, machine_expr);
+ g_print(" test%d = import \"%s\";\n", i, machine_expr);
g_print("}\n");
_______________________________________________
nix-commits mailing list
[email protected]
http://lists.science.uu.nl/mailman/listinfo/nix-commits